1 person found this helpful
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
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?
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...
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?
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.
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?