DOCUMENT_ROOT - Undefined index

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thomasv
Forum Newbie
Posts: 3
Joined: Mon Dec 09, 2002 6:42 pm

DOCUMENT_ROOT - Undefined index

Post 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?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

try running a phpinfo(); page in that same directory and see if it is listed with the other $_SERVER vars.
thomasv
Forum Newbie
Posts: 3
Joined: Mon Dec 09, 2002 6:42 pm

Post 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.
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post 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'])));
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you're running PHP as cgi, aren't you? Then DOCUMENT_ROOT is not set.
For modules it is
thomasv
Forum Newbie
Posts: 3
Joined: Mon Dec 09, 2002 6:42 pm

Post by thomasv »

Thanks guys, I've now switched to modules and all my old works :)
Post Reply