Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Need help with PHP Includes please



9:36 am on Aug 2, 2012 (gmt 0)

Our website has expanded a lot since we started it and now I've been asked to add on more pages. This means updating the navigation on every. single. page. And obviously, I don't want to have to keep doing this. My only thought is to use PHP includes, however as I have never used PHP before, except for our e-mail forum, I'm not quite sure what to do.

I understand the whole creating a new PHP page just for the navigation and linking it to the other pages, however, will I have to change all of the website pages to .php? At the minute they are .html / .htm.

If I change them all, do I have to remove the .html / .htm ones from my hosting server and replace the pages with the .php ones?

Will having every page as .php affect the website?
Will it make it quicker to load or slower?
How will Google know that the pages have been changed?
Will it affect our Google rankings?

Yes, I'm confused. Your help is much appreciated!


11:40 am on Aug 2, 2012 (gmt 0)

With regard to the replacing .html with .php, you can keep the same extensions for your pages by using this command in an .htaccess file

AddType application/x-httpd-php .htm .html

This command instructs your web server to execute php code inside web pages with .html extensions.

Inside your .html web page you can then have code like this


which will be executed.

The nav.php file can contain html code for your nav menus.

Then for any future changes, you simply change nav.php once and all your page that include nav.php change as well.

There will be a slight slowing down of page load, but I think it would be negligible.

Google hopefully will be crawling your pages on a regular basis and will pick up on any additions to your navigation, regardless of whether you add them manually to each page or use the nav.php include.

Again using the hard-coded nav or nav.php include should not affect your rankings.

Hope that makes sense.


5:12 pm on Aug 11, 2012 (gmt 0)

5+ Year Member

If what you wish to include is static,
you do not have to use php includes.
Simply use includes for the static text:

<!--#include file="footer.html" -->



9:11 am on Aug 13, 2012 (gmt 0)

Sorry, I posted this question on several forums and I forgot about this one until I got the e-mail notification.

JohnNZ: Thanks very much for your reply. As I've heard, and as you've said: There will be a slight loading, but not too bad. However, even if it isn't too noticeable, my manager isn't too keen on the idea so I think I'll look into other ways.

Jonesy: Thanks for your reply. I attempted this, but it didn't seem to make any affect. However, I was only viewing it through notebook onto my browser. Would it only show an effect if I uploaded it onto my hosting server?


9:57 am on Aug 13, 2012 (gmt 0)

Okay, so I put my question to the test and it never worked on the hosting server. However, once I changed the filename to .shtml it worked. This bothers me as it means I'll have to change all of my pages to .shtml and this will just confuse Google.

I suppose nothing is ever simple.


11:21 am on Aug 13, 2012 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

All you need to get SSI to work on html files is something like
AddHandler server-parsed .html
or you could try
AddOutputFilter INCLUDES html
in your configuration



12:54 pm on Aug 13, 2012 (gmt 0)

I tried out the SSI and it worked, however our page was very, very slow to load.

However, our navigation is made by javascript as it's a drop down nav, do you think this is the cause of the slow loading? Would it be best to have a simpler nav?


1:30 pm on Aug 13, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Hi there,
I use php includes in my pages for navigation and other things, like ads, headers and footers, etc.
I didn't notice any slowing of page loads when I implemented this, and, for all pages but the first downloaded, I imagine the loading should actually be faster, since the include is already in the browser cache.

I am also using drop down menus, but I'm using css to achieve these. I think this might be a better alternative to javascript for both speed and useability. No need for javascript active and everything is in a once downloaded css file, for the whole site.
You can search for 'css drop down menus' for lots of ways to do this simply.

All of my new pages are written as .php although they are in standard html.
I also wonder about a good way to change all of my old pages to .php, with minimum SE upset, but as yet have not investigated this too seriously.... since everything works with the .htaccess file's help!


2:09 pm on Aug 13, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

AddType application/x-httpd-php .htm .html

This command instructs your web server to execute php code inside web pages with .html extensions

Does anyone have a clue on how this affects server load?

Thanks for any insights.


2:11 pm on Aug 13, 2012 (gmt 0)

tbear: Thanks for your reply.
Huh, this is rather strange then. I wonder why it's loading slowly for us. In all honesty, the whole website needs revamped as when I first created it, we only had a few pages. Now that it's expanded, it's a bit of a mess.

I'm hesitant about using includes in case I do something wrong, but it will certainly make things easier.


4:27 pm on Aug 13, 2012 (gmt 0)

WebmasterWorld Administrator 5+ Year Member Top Contributors Of The Month

Adding AddType application/x-httpd-php .htm .html to your htaccess file may or may not work, it depends on how your host's server is configured. The best way to get it right is to ask your host.
I went through the changes you describe several years ago for keeping navigation up to date. The .php includes will not show up on your desktop unless you are using a desktop server for your development.
Some things I learned from trial and error are:
1. make sure the character set and doctype for your includes matches the page they are included on. If you are using Windows the UTF-8 character set often uses "UTF-8 with BOM" that can leave a funny looking character in the page (it is a Byte-Order-Mark).
2. Clip out a block of text to use for your include that won't affect your page layout if for some reason it fails to process. Have more than one size (length) of page navigation to use as an include because you don't want people to view a page that is full of whitespace caused by a menu column that stretches the page length.
3. The best way I found to create your nav include is to use a page that you would like the other pages' navigation to resemble and simply cut out the text between the <container> tags whether div, td or p tags, paste it into a new text file and save it as nav.php or whatever you want your include to be called.
I imagine it is possible that including a javascript menu as a .php include might cause issues because the include is processed (parsed) before loading and your include file lacks html functionality outside of its included spot on the page. That is, the include could not parse the javascript before loading it, I would look for css dropdowns as tbear suggested above.


4:52 pm on Aug 13, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

not2easy is quite right about asking your host to apply the .htaccss code. That is exactly what I did. Also regarding having a desktop server (I use xampp).

You can always create a test page, to put on your server, to try things out before using stuff site wide. That way you won't get any nasty surprises.

I'm almost sure your javascript may be slowing things.

I have just implemented a multi-tiered drop down menu, just to keep the main menu size down to about 6 main categories, then using subs for each page. The two reasons are to contain the size and so as not to confuse visitors with too many choices.

Good luck!


8:51 am on Aug 14, 2012 (gmt 0)

Thank you very much not2easy and tbear!
I'll put those suggestions into action. I've never been the biggest fan of javascript anyway so I'll definitely switch the nav to css.

If I have any more problems (which knowing me, I will) I shall be back. ;)


Featured Threads

Hot Threads This Week

Hot Threads This Month