View Full Version : Headers and Footers

08-18-2013, 10:05 PM
Hello all.

A question that someome probably (hopefully) will have an answer for.
I am working on a large website and would like to work with a single header and footer stored in the root directory.
I am using the <?php include 'header.html'; ?> command to load the header. It only works if I put a header and footer in every directory of my site (ending up with about 20 headers and footers).
If I have for example siteroot/school/class/student1.php. To make the header, footer work, I will have to place it in the siteroot/school/class/ directory.
This is of course not what I want.
How can I point to the header and footer in the root folder using the include command, or do I have to do something completely else?

Many thanks!

08-19-2013, 01:18 AM
the <?php include(''); ?> wil include what you want it to soits justa question of changing the path.
As a rule i leep my incluning files in a folder named ie. incl
so the path is
<?php include('incl/file.php'); ?> or
<?php include('../incl/file.php'); ?> etc.
jusrt a word of caution , if yu include an html page into your work , do not have the headed info in it as this can throw an error, only the content you want to include is needed

08-19-2013, 09:00 PM
The <?php include('../incl/file.php'); ?> works fine for directing to the footer and header in the root folder. The problem is that the links on the footer and header not work. For example again:

siteroot/school/class/student1.php has a <?php include('../incl/file.php'); ?> code for the footer. The footer of course appears. Now the footer contains a link (something like, "for more info, contact us here"). If the contact page is in the root (siteroot/contact.php), the link <a href="contacts.php" title="contacts">Contacts Page</a> on the footer should take you to the contact page. This does not happen.... It wants to open siteroot/school/class/contact.php.
So although the footer is in the root, any link on there thinks it's still in the deeper directory of the original document (student1). Hope this make sense. It's not just the footer, but of course all the links in menu's in the header act the same behavour. Hope you can help?

08-20-2013, 01:07 AM
the best thing to do would be to use an absolute link as in

<a href="mysite.com/contact.html">Contact us</a>

08-20-2013, 09:48 AM
Or you could use the only the forward slash to indicate that 'contact.php' is in the root directory.

<a href="/contact.php">Contact us</a>