Jump to content

*Portably* Keeping Track of a Site's Root Directory


Jesdisciple

Recommended Posts

I have a dilemma: The path to my site is different on my deployment server than on my development server. I was using relative paths to get around this, but that presents problems when used in include files; the script's working directory isn't always the same and so relative paths break. I now use cookies, but this method assumes that the file by which the user enters the site is in the root directory. Does anyone have a suggestion?Thanks!

Link to comment
Share on other sites

Hmm, maybe the server variable would work:$_SERVER['HTTP_HOST']."/folder/file.php"And maybe giving different directories based on the host:switch($_SERVER['HTTP_HOST']) {case "mydomain.com":$root="mydomain.com/myfolder/";break;default:$root = "/";}And well, there's the thing of starting the URL with a slash to indicate the root of the server:/folder1/folder2/file.phpI'm not sure what else might be of help.

Link to comment
Share on other sites

$_SERVER['HTTP_HOST'] could be useful for the "outer root" as I call it, the site's root from the client's perspective. The problem with this is that my development server has the site as a single project among others, so my site is in a subdirectory of localhost/.The switch is a great idea, and it will help with the "inner root" as well.As for the beginning slash: That would work for the "outer root" but not in the switch, so $_SERVER['HTTP_HOST'] trumps it.EDIT: JSG, that's what I was doing with the cookies, but I hadn't considered a server-specific include yet.Thanks again!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...