This tutorial will teach you the very basics on how to use a PHP #include command. The #include command is used to insert the content of an external HTML page into an existing PHP page. For example, the header and footer of this page you are reading right now are actually external files which are loaded into the page when you request the server to display the page. Using this technique makes it easier to update the header of all the pages of our website by simple updating a single included header file without having to update any code in any of our pages.

This technique can be used anyone without having any advanced PHP knowledge. This tutorial will teach you how to use this command.
Our tutorial is divided into two main sections:
- Server Requirements
- Code Implementation
Server Requirements
In order to run this command you will need to have PHP installed on your server. You can check this with your hosting service provider. Any modern version of PHP will be sufficient to execute this command. Other than that, there are no specific server requirements.
Code Implimentation
We are going to create a very simple example in which a HOME page includes a HEADER into it. This means that we are going to need two pages the HOME page and teh HEADER page.
We will start off with the header page. Using any web editing tool, simply create an HTML page with the following content:
Note that you do not need to create a proper HTML file with <html>, <header>, or <body> tags, simply because our header page will not be displayed by the browser by itself and instead it will be included as part of our HOME page.
Save this file as header.html.
It is now time to create our HOME page. Using any web editing tool, create an HTML page with the following code:
<head>
<title>My Test Homepage/title>
</head>
<body>
</body>
</html>
Our page does not have anything in it yet other than the page title tag. We are now going to add our #include command in the body of the page:
<head>
<title>My Test Homepage/title>
</head>
<body>
<?php include(“header.php”); ?>
</body>
</html>
That should insert our header at the start of our body when our page is displayed on the server. If you want to have other content in your page you can simply insert it below that tag.
<head>
<title>My Test Homepage/title>
</head>
<body>
<?php include(“header.php”); ?>
<h2>Welcome!</h2>
<p>Thanks for visiting my website, I hope that you have a great time here!</p>
</body>
</html>
That should do it. You now have to save this file as home.php. You file MUST END WITH THE .PHP EXTENSION FOR THE SERVER TO PROCESS THE COMMAND. DO NOT FORGET THIS.
That should do it, you will not be able to test this command on your computer unless if you have a PHP server installed. The easiest way to try this is to upload it to your server. Simply upload both files to the same directory and then access home.php to see the content of your header.html file displayed in there along with your home page content!
You might also like
| The “If” Conditional Basic ActionScript Conditionals are special tools that add logic to an ActionScript program by taking an action only upon the satisfaction... | Adobe Fireworks Save Paths as ActionScript3 FP10 This command will let you export a selection of path objects to ActionScript using the new ActionScript drawing... | The Display List in AS3 The display list is the system by which objects are displayed on the screen using ActionScript 3.0. It is one of... | AS3 Linking to External WebPages This tutorial will teach you how to use ActionScript 3.0 to link from your Flash project to another webpage using... |








