Click to See Complete Forum and Search --> : How can I get the web root in IIS+PHP?


Anon
09-25-2001, 10:26 PM
In Apache+PHP,I can use $HTTP_SERVER_VARS["DOCUMENT_ROOT"] to get the web root directory, but how can I get it in IIS+PHP?

mithril
09-26-2001, 06:13 AM
$HTTP_SERVER_VARS["DOCUMENT_ROOT"] works on both. Beware though that IIS reports the path using Win32 backslashes instead of *Nix forward slashes (Win32 Apache reports the sensible way... forward slashes.

geoff

Anon
09-26-2001, 10:11 PM
But in my IIS+PHP,the $HTTP_SERVER_VARS["DOCUMENT_ROOT"] is empty,Why?

mithril
09-27-2001, 07:55 AM
That I don't know. Are you using $HTTP_SERVER_VARS["DOCUMENT_ROOT"] in a function? If so, have you either passed $HTTP_SERVER_VARS in as a argument, or declared it global? That seems to me to be the most likely reason. You can get a full listing of all environment variables (and their values) by calling phpinfo().... the env. vars are listed at the bottom of the output. HTH.

geoff

Anon
09-28-2001, 01:53 AM
But I didn't use it within any function.
Using phpinfo() in Apache+PHP can tell the $HTTP_SERVER_VARS["DOCUMENT_ROOT"],but in IIS+PHP you can't get that.

pure_mourning
09-30-2001, 10:17 AM
i have the same dilema.. i solved it like this...

in each of you .php files put this at the top..

<?
$path_to_root = "../../";
$absolute_path = realpath($path_to_root);
?>

where $path_to_root is the relative path to your root directory. It's a bit messy, but it's the only way i can do it without $DOCUMENT_ROOT. oh, and btw, u can get either of those vars anywhere in your scripts with $GLOBALS['absolute_path'] or $GLOBALS['path_to_root']

etc.

hope this helps;

Ben

Anon
10-07-2001, 10:25 PM
Thanks for your help.
Yes,That's a good idea.