PHP Includes - one file for everything

james169

Recruit
I am not much of a programmer, as I deal mostly with back-end server administration, but I thought I would lend likely the most valuable and time saving code snippit that I have came across for those of you that are interested.

Basically, this thread is about how to make one file, and have it displayed on all pages of your website. Why would this be useful? Well, for example if you had a header, footer, or navigation that is site-wide, you can edit ONE FILE and have it displayed on all pages of your website.

Imagine editing only one file instead of every page on the site when you need to add a new link to your navigation bar, or, in the example of glowhost.com, a common footer on every page.

Have a look:

http://glowhost.com/footer.php

Look familiar? If we need to edit a link or change something in the footer, we edit the one file, and it appears on every page in our website.

What a time saver!

To achieve this, it is a simple process.

First of all, you will need to make sure your document that includes any file like this to have a .php. extension, instead of .htm or .html

Lets now assume that you have your page named whatever.php, and in whatever.php you want to include a common footer like GlowHost.com does.

ll you need to do is make a page called footer.php (or whatever suits you best) and code it like a normal html document.

Now open up whatever.php in your html editor, and place this snippet in where you would like the footer to appear:
 
Back
Top