Page 1 of 1

DOCUMENT_ROOT - Undefined index

Posted: Mon Dec 09, 2002 6:42 pm
by thomasv
I'm trying to access the DOCUMENT_ROOT variable as listed under the _SERVER superglobal in the PHP manual. I keep getting the Undefined index error no matter what I do. I have tried both $_SERVER['DOCUMENT_ROOT'] and $DOCUMENT_ROOT (with registar_globals switched on).

I can access other _SERVER variables. I treid PHP_SELF and PATH_TRANSLATED which both worked fine. I'm completely stumped, has anyone else come across a similar problem or can think of a reason why this might be happening?

Posted: Mon Dec 09, 2002 7:45 pm
by mydimension
try running a phpinfo(); page in that same directory and see if it is listed with the other $_SERVER vars.

Posted: Tue Dec 10, 2002 6:32 am
by thomasv
Thanks, I can see now that the document_root variable isn't listed. I'm running IIS so I guess it just doesn't support it.

Posted: Tue Dec 10, 2002 9:01 am
by hedge
This is what I use, I set my own constant HOMEFS and this works on either:

Code: Select all

if (isset($_SERVERї'DOCUMENT_ROOT'])) define('HOMEFS', $_SERVERї'DOCUMENT_ROOT']);
   else define('HOMEFS', str_replace(str_replace("&quote;, "//",$_SERVERї'PATH_INFO']), "", str_replace("\&quote;, "/",$_SERVERї'PATH_TRANSLATED'])));

Posted: Wed Dec 11, 2002 2:26 am
by volka
you're running PHP as cgi, aren't you? Then DOCUMENT_ROOT is not set.
For modules it is

Posted: Wed Dec 11, 2002 5:48 am
by thomasv
Thanks guys, I've now switched to modules and all my old works :)