• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

help with relative linking and php includes, please!

morkus64

Diamond Member
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?
 
Try ./php/ in the root and ../php/ in any subfolders.

I'm guessing the PHP code is using linux file paths not website URLs.
 
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
 
Back
Top