Many websites created today are created from automated php scripts such as blogs or content management systems. These types of sites rely heavily on php include statements to build the website.
If however you build your own static page websites, where each page is individually created by hand, you could still benefit from the use of php include statements. By using these include statements you can greatly decrease the amount of time it takes to edit or create new pages for your site.
Most websites can be sub divided into 4 or 5 sections:
Left Menu Column
Content Area
Right Menu Column
Footer
In a static multi page website if you want to change the header, footer, left or right menu then you need to make the same alteration on each individual page. For example, if you add a new page then you would have to add this page to the menu on every other in your site. This isn’t to much of a problem on small sites with only a few pages, but can be time consuming once you get 10 pages or more.
If you use php include statements then you can create separate php files for each component of your site and include them into your website template. Then if you want to make a change all you need to do is edit one file, and it will appear on all of your pages.
Lets take a look at a quick example. We will create a basic template to see how it works. Open your favourite text editor such as notepad and create a file called index.php and copy the following into it.
Now create a file called header.php and copy the following into it
Now create left-menu.php for your left menu with the following code
Now create right-menu.php for your right menu with the following code
Now we just need a footer.php
Copy the five files to a folder on your server and then navigate to the index.php to see the result. To see how easy it is to edit, duplicate the index.php a few times, changing the text in the content area and save save them as page1.php, page2.php, page3.php and so on. Upload them to the same folder on your web server as the other pages. Open the left-menu.php and change the links for the menu items to suit, and overwrite the file on the server with this edited file.
Now if you visit your new site you will see that the links are functional on all pages. If you add another page then you only need to edit left-menu.php, to have it appear on all of your websites pages.
For this to work you will need to save your pages with the .php extension, if you use .htm then your includes will not appear. If you want more information on basic php visit the downloads area of this site and download ‘I Hate PHP’.



