PHP Includes
You can set up your HTML pages so that you only have to edit one file for your navigation. The solution can be found in using PHP Includes. PHP is a type of coding like HTML that is only supported by certain servers. Free servers may not support PHP - check to see if your host provides PHP Support along with your package. This tutorial does not require you to use frames and may be used with div layouts and table layouts. You will have to change all your pages to the extension .php for example: home.php avatars.php links.php and so on. Remember that you cannot view this without uploading it onto a PHP supported server - in other words, you cannot view these pages offline on your computer, which is unfortunate.
Part One: Creating the File
Below is an example of a page we want to use PHP includes. You can copy this section of coding and use it to for this tutorial if you do not have your HTML pages ready.
<html>
<head>
<title>PHP Includes Tutorial</title>
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<body>
<div style="position: absolute; left:0px; top:0px; width: 240px">
<img src="main.jpg">
</div>
<div style="left: 334px; top:280px; position: absolute; width: 186px">
<p class="head">Category</p>
<a href="#">link goes here</a><br>
<a href="#">link goes here</a><br>
<a href="#">link goes here</a><br>
<a href="#">link goes here</a><br>
</div>
<div style="position: absolute; top: 20px; left: 200px; width: 287px">
<p>About the Site</p>
<p>Welcome to Reminiscent Tutorials, created by Sarah.</p>
</div>
</body>
</html>
Part Two: Creating header.txt
Highlight and cut the bolded text from your html page as indicated below. Open another file and paste this section. Save this document as header.txt *remember to save as .txt or it will not work*
<html>
<head>
<title>PHP Includes Tutorial</title>
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<body>
<div style="position: absolute; left:0px; top:0px; width: 240px">
<img src="main.jpg">
</div>
<div style="left: 334px; top:280px; position: absolute; width: 186px">
<p class="head">Category</p>
<a href="#">link goes here</a><br>
<a href="#">link goes here</a><br>
<a href="#">link goes here</a><br>
<a href="#">link goes here</a><br>
</div>
<div style="position: absolute; top: 20px; left: 200px; width: 287px">
<p>About the Site</p>
<p>Welcome to Reminiscent Tutorials, created by Sarah.</p>
</div>
</body>
</html>
Part Three: Creating footer.txt
Do the extract same for this next bolded selection, but save as footer.txt in a new file instead.
<p>About the Site</p>
<p>Welcome to Reminiscent Tutorials, created by Sarah.</p>
</div>
</body>
</html>
Part Four: Creating main.php
What you are left with should be this part:
<p>About the Site</p>
<p>Welcome to Reminiscent Tutorials, created by Sarah.</p>
In this same file, surround your header and footer files around your main content using PHP code called the Include Function:
<? include ('header.txt'); ?>
<p>About the Site</p>
<p>Welcome to Reminiscent Tutorials, created by Sarah.</p>
<? include ('footer.txt'); ?>
Save this file as main.php (or whatever you would like to call it). By adding these codes above, you are including header.txt and footer.txt into this page without having to enter the whole code in. You can change all your other HTML files in this way. Just leave the content and insert the header.txt and footer.txt with these given codes. To change links on your navigation, go to header.txt and edit - what you edit there will change on all the pages where you included header.txt - neat isn't it?
Reminiscent Designs, my other website, is coded in this fashion. Just make sure to change all your extensions from .html to .php (this is the most important part along with having PHP Support). I have been asked if there are special programs that will give you .php extensions and there are a few that you can download free trials online. However, I simply use Notepad, a Text Editor that comes long with my Windows XP.
Recap
OK so let us recap everything. You should have the following files:
header.txt
main.php
footer.txt
header.txt - includes everything that goes BEFORE your content. (css, navigation…etc)
main.php - includes your content for that page.
footer.txt - includes everything that goes AFTER your content.
This is not the only use for PHP includes, but it is the most common. You can insert any file as long as its hosted on your server and is in .txt format.
[ Download File(s) from Tutorial ]