If you think that title is a little confusing, wait until you read the rest of this. I’m going to try my best to break it down. I need some help setting my php include paths to work relative to the root. Now I’ve spent alot of time searching, reading, and playing with some options but I can’t seem to get it to work the way I need it to.
I’ve found:
[php]
<?php $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/common/header.php"; include_once($path); ?>[/php]
[php]< ? php require_once $_SERVER[‘DOCUMENT_ROOT’] . ” /common/header.php ” ; ? >[/php]
[php]
// This is the one I am using. I have this code posted at the top of my php documents.
Each of the above codes work in one way and not the other. In my files I am using the third option.
Here’s the situation…
I have a hosting account with godaddy that allows for multiple sites within the same host. Basically shared hosting.
The main domain has a DOCUMENT_ROOT of /var/chroot/home/content/xx/xxxx/html
Then each additional domain is setup with a SUBDOMAIN_DOCUMENT_ROOT.
In this case the SUBDOMAIN_DOCUMENT_ROOT is /var/chroot/home/content/xx/xxxx/html/xyz_site
Now when I’m building this site in Dreamweaver I’ve setup xampp to point to the main xyz_site folder. So while on my local host DOCUMENT_ROOT works just fine. All relative paths work.
NOW
When I load the files to my godaddy server the relative paths no longer work because the paths are working from the DOCUMENT_ROOT and not the SUBDOMAIN_DOCUMENT_ROOT. If I change the code above code from:
[php]
<?php set_include_path( implode( PATH_SEPARATOR, array( $_SERVER['DOCUMENT_ROOT'], get_include_path() ) ) ); ?>[/php]to
[php]
<?php set_include_path( implode( PATH_SEPARATOR, array( $_SERVER['SUBDOMAIN_DOCUMENT_ROOT'], get_include_path() ) ) ); ?>[/php]My site will work on the godaddy server but not on my local host. I’ve tried to find a way to reconfigure my xampp to have a subdirectory so I can match the 2 configurations but so far no luck. What I would like to know is there a way to code this differently? I’m going to have 100 +/- pages once this is done so changing the DOCUMENT_ROOT >> SUBDOMAIN_DOCUMENT_ROOT is going to be a real pain.
I hope this all makes a little bit of sense. Please let me know if you have other questions. Any help would be much appreciated!