Click to See Complete Forum and Search --> : PHP includes in Subdirectories


paishin
02-15-2008, 10:38 AM
Hello,
first of all I would like to say hi to all, this is my first post to your forum.

I am building a site using php, the main page is devided into 3 parts header(header.php), container (page I want to be displayed in the container div), footer (footer.php).

This configuration works fine when header.php and footer.php are in the same folder as the container page

The problem is that when the container page is in a subdirectory then including the header/footer . php using <? include '../header.php'; ?> results in loading the header without the images (links are incorrect).

Any suggestions on how to fix this, without creating duplicate header/footer files?

NogDog
02-15-2008, 10:41 AM
Use absolute paths to the images, e.g.:

header.php:

<img src="/images/image.jpg" alt="">

Note the leading "/", which in this context refers to the root web directory for this site.

paishin
02-15-2008, 11:04 AM
OMG!

I cant believe that the answer was so simple. I have been searching the web for over 3 hours for this!!!

Thank you NogDog!!

so if i get this right using '/directory/file.php' means root/directory/file.php where as 'direcotry/file.php' means current_direcotory/directory/file.php ???

NogDog
02-15-2008, 11:29 AM
You got it. :)

Don't confuse the HTML path syntax with PHP file system paths, though.