/    Sign up×
Community /Pin to ProfileBookmark

PHP includes in Subdirectories

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?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 15.2008 — Use absolute paths to the images, e.g.:

header.php:
[code=html]
<img src="/images/image.jpg" alt="">
[/code]

Note the leading "/", which in this context refers to the root web directory for this site.
Copy linkTweet thisAlerts:
@paishinauthorFeb 15.2008 — 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 ???
Copy linkTweet thisAlerts:
@NogDogFeb 15.2008 — You got it. ?

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

Success!

Help @paishin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...