1:07:00 AM
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: 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. 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 , 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: 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: 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. Thanks for visiting my website, I hope that you have a great time here! 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! This concludes our tutorial. I hope that you learnt something new from it. If you have any questions or comments feel free to post them at the forum. - End of Tutorial
Server Requirements
Code Implimentation
Oman3D - The Creative Adventure!
Welcome!
0 Responses to "Using the PHP Include Command"
Post a Comment