help with relative linking and php includes, please!

morkus64

Diamond Member
Nov 7, 2004
3,302
1
81
I'm not quite sure what's going on here. I'm trying to include a header, navigation menu and legal text on each of my pages, so I thought i'd try my hand at php. Here's what i have set up:

index is in the root (obviously)
header.php and legal.php are in /php

I want to make a template page that i can use everywhere, from the index.php in the root to contact.php in /contact so i'm using <?php include("/php/header.php"); ?>

this should mean that it is looking for header.php in root/php/ correct?

Yet I'm getting an error:

Warning: main(/php/header.php): failed to open stream: No such file or directory in /home/content/a/l/u/alubkin/html/index.php on line 53

Warning: main(/php/header.php): failed to open stream: No such file or directory in /home/content/a/l/u/alubkin/html/index.php on line 53

Warning: main(): Failed opening '/php/header.php' for inclusion (include_path='.:/usr/local/lib/php') in /home/content/a/l/u/alubkin/html/index.php on line 53

i'm presuming that /home/content/a/l/u/alubkin/html/ is godaddy's server's directory for me, and that /php would look for /home/content/a/l/u/alubkin/html/php/. Is that correct? It's not trying to look for something in the root of godaddy's server is it?

what am i doing wrong?
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Try ./php/ in the root and ../php/ in any subfolders.

I'm guessing the PHP code is using linux file paths not website URLs.
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0
usually you can set a default php include path, that way all your included files can be in a single non browsable directory

and then all your include code can use the same path (no matter where the script is)

depending on your setup, you can set this path via htaccess or with a php.ini file