Web Shoppe
Home | Downloads | Useful Scripts | PHP and SSI Includes

PHP and SSI Includes

Say you had a 20 page website with the same layout and navigation on every page. Every time you wanted to change the layout or the navigation, you'd need to edit all 20 pages to match. What a chore!

If your server supports either PHP or SSI, there is a much easier way.

Create two text files, one called "header.txt," the other called "footer.txt". In those files, place the header and footer code from one of your HTML pages. Here are some examples:


header.txt
<html>
<head>
<title>MyPage</title>
</head>

<body bgcolor="pink">
<font face="Arial" size="2">

 
footer.txt
<p>
<center><a href=index.html>home</a>
</center>
</font>

</body>
</html>

Then, go through your pages, and replace the HTML headers and footers with this:

<?php include('header.txt'); ?>

This is where the main body of content would go.<p>
It can contain HTML code, just like a regular page.

<?php include('footer.txt'); ?>
And rename them to .php files rather than .htm or .html. Now you only have to edit the header and footer files, and all your pages will reflect the changes!

Note: If all your files are in the same directory, you can just link to 'header.txt', but if you have several directories, be sure to change the location to point to the file, eg: '../header.txt'.

You can do the same thing with SSI, if your server doesn't support PHP. Instead of using the <?php include ?> code, use the following code:

<!--#include file="header.txt" -->

This is where the main body of content would go.<p>
It can contain HTML code, just like a regular page.

<!--#include file="footer.txt" -->
And rename the files from .html to .shtml, so that the server knows the file includes SSI. Note that there is no space after the <!-- but there is one before the -->, that is important.

That's it!

 

about this site
site map
forums
ask a question
link this site

html tutorials
css tutorials
php tutorials
javascript tutorials
htaccess tutorials

graphics design
graphics tutorials
website design
internet copyright

about domains
about web hosting
hosting tutorial
xentrik hosting
ftp tutorials

stats logger
search engines
code generators
button labeller
remote services

font archive
website layouts
website graphics
useful scripts