How does PHP Include
My example below illustrates how to make the top and
navigation elements of your web page dynamic. This will
enable you to update 1000s of pages by just editing two
1. Make sure your web host has PHP installed. Most
reputable hosts do but check with them anyway.
2. Place the content between each of the comment tags
(ie <!--HEADER --><!--HEADER -->) in a text file and name
it with a .php extension ie header.php (or header.txt) You
can use notepad for this.
Here is an example of a typical web page using CSS
(cascading style sheets) to style the header content ie
<title> This is the page title </title>
<h1 > This is the header</h1>
<li><a href="aboutus.php">ABOUT US</a>
</li> <li><a href="contactus.php">CONTACT US</a></li>
<li><a href="aboutus.php">ABOUT US</a></li>
<li><a href="contactus.php">CONTACT US</a></li>
3. Name the other include files ie topnav.php and
4. Create a folder called includes and place the
header.php, topnav.php, leftnav.php files in it.
5. Replace the text between the comment tags with
includes code. i.e.
<div id="header"> <h1 > This is the header</h1></div>
<?php include 'includes/header.php'?>
Do the same for the topnav and leftnav sections.
7. Save your new web page with a .php extension ie
index.php (If you save it with a different extension your
page will get errors when you upload it to your server.
8. Upload your includes folder and CSS style sheet
created one) to the root folder of your server...usually
it's the public_html folder.
9. Open the new web page in your browser. The
top navigation and left navigation sections should appear.
Experiment with changing your include files or making
areas of your web page dynamic. You can then do the same
for future web sites you build and save lots of time
Frequently asked questions:
How can I use PHP include for easy site
maintenance if all my web pages currently have .html or
.htm extensions? I don't want to lose their current search
Insert the code below into notepad, name it
.htaccess and upload it to the root folder of your server.
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
Now just follow the 9 steps as outlined above and you will
be able to keep your current page extensions ( .htm..html
or .php) and still use PHP include. This will allow you to
keep the same search engine rankings as you had before you
made your site dynamic.
How can I include content from other sites
using PHP include (not possible using SSI)?
Insert this code on your web pages:
What PHP include code do I use for web pages
if they are positioned one or several directories away
root files of my server? I keep getting errors when I
The best way is to use the full path from the site URL. ie
<?php include 'http://www.domainname.com/directory/includes/topnav.php'?>
Herman Drost is a Certified Internet Webmaster (CIW)
and owner of iSiteBuild.com
Web Site Design, Web
Hosting, Web Site Promotion
Author of “Marketing Tips” newsletter. To subscribe, enter
your information at: