PHP Includes

When you make changes to your site (add another link to your navigation, completely change the layout, etc.) you probably have to make changes to all 172 HTML files. Right? Do you wish you could just change it once? You can (if your host allows PHP, anyway).

PHP can include the contents of a file in a page with the statement <?php include ‘file.ext'; ?>. Just replace file.ext with the name of the file you want to include (like pizza.html) and change the extension form .html to .php, I should probably explain better.

Right now your file (we’ll call it index.html) probably looks like this (this is example, your layout is probably more complicated):
<html>
<head>
<title>My site</title>
</head>
<body>
content
</body>
</html>

Cut and paste (cut not copy) the following from index.html into a new file called header.php. Then save it. Here’s what you should cut and paste: <html>
<head>
<title>My site</title>
</head>
<body>

Then cut and paste
</body>
</html>

into a new file called footer.php. Save it. Your index.html page should now look like this:
content
Change it to look like this:
<?php include 'header.php'; ?>
content
<?php include 'footer.php'; ?>

Save it and rename it index.php. If you view it off the server, it should look like normal. If you change the header and footer files, the changes will take effect on index.php and any other files with the PHP includes in it. If you view the source it looks like normal, you can’t tell you used PHP (except for the .php in the filename). You’ll also have to update all the links on your site to say file.php instead of file.html.