5 Replies Latest reply on Apr 27, 2010 10:33 PM by martcol

    Help Please With Header/Footer Includes

    Stuart Haiz Level 1

      Can someone please help with an easy to follow answer?


      I am building a site and want to use the header and footer as include files to make maintenance of the links easier. In the header, the navigation is rollover graphics. (I mention this because there is an issue with the image paths.) I have been able to get the includes showing up and working, but my problem is that I wish to use subfolders and it's here I'm going round in circles. The graphic navigation is visible at the root level only.


      My site structure goes like this:


      Root has index.php and a couple of other pages, plus the following directories, css, images, includes (containing my header.php and footer.php), subfolder1 (containing index.php) and subfolder2 (containing index.php).


      The navigation works on the root level but not at the sub-level. I have tried using both document and site relative links, ../ as well as / and./ paths but I can't figure this out.


      My navigation is HOME | SUBFOLDER1 | SUBFOLDER2 | CONTACT | LINKS. Hope this is clear.

        • 1. Re: Help Please With Header/Footer Includes
          martcol Level 4

          Server side includes are great for doing what your doing.


          Sounds to me like you understand the different types of URLs you can use but you will need "site root relative" urls in your links in your include file.  You will also need to think about the path in your include but I imagine you know that.


          If you have a link in your navigation and it links to a page in a folder then your link must include the full path e.g.


          <li><a href="/pages/cv.php" title="Curriculum Vitae">CV</a></li>


          If your included file is in a folder and not the root you will need to declare its path


          include 'pages/menu.php';


          If you want a tutorial on this try:





          I'm not sure what else to suggest really except that you add a bit of the code from your file and include file?



          1 person found this helpful
          • 2. Re: Help Please With Header/Footer Includes
            Stuart Haiz Level 1

            Hi Martin


            Thanks for your reply, the advice and the 2 very helpful links. I haven't resolved this yet and am still working on it.The problem is that my included header works perfectly ok at root level, but not when it loads into a page in a sub-directory. (The header.php is at root level now too, but that wasn't the issue.)


            At root level a link is something like this: http://localhost/website/folder1/index.php which is fine. However, when I go to that sub-directory, the same link becomes this: http://localhost/website/folder1/folder1/index.php. This is using a doc relative link. If I use a site root relative link, the link becomes this: http://localhost/folder1/index.php.


            I'm using MAMP. Do I need to edit my hosts file somehow because it looks like this will work on the server?


            Otherwise, I've been looking around the net and wonder if I need an .htaccess file or something that tells my localhost (and my live site when I've got it working) what the base url is etc...

            • 3. Re: Help Please With Header/Footer Includes
              martcol Level 4

              If you want to PM me with your email, and you think it might help, I can send you one of my files and the file I use for an include so that you can see what works for me?



              • 4. Re: Help Please With Header/Footer Includes
                Stuart Haiz Level 1

                Hi Martin


                I have got this working! Your advice with the site root relative links inside the includes was part of the solution so thank you.


                For everyone else, the final part of the puzzle was to set up Virtual Hosts on my system. Being on a Mac I use MAMP and found a post here that helped me: http://forums.macrumors.com/showthread.php?t=749072


                Now I have my includes in an includes directory and the images and links are all using site root relative paths such as:


                <a href="/contact.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('contact_btn','','/img/contactBtnOver.png',1)"><img src="/img/contactBtn.png" alt="Contact" name="contact_btn" width="70" height="36" border="0" class="mainBtn" id="contact_btn" /></a>


                This means as long as I use the right path when including the header in the first place (<?php require_once ("includes/header.php"); ?> from root level or <?php require_once ("../includes/header.php"); ?> from a sub-directory) everything works.

                • 5. Re: Help Please With Header/Footer Includes
                  martcol Level 4

                  Stuart@DM wrote:

                  I have got this working!



                  Well done Stuart!  Looks as thought your persistence paid off.  Don't you just love it when a plan comes together?