error while using server variables

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
czarnick
Forum Newbie
Posts: 4
Joined: Sun Jul 30, 2006 1:44 pm

error while using server variables

Post by czarnick »

hi all

i am new to this forum n also to php
my problem is that i am getting error when using $_SERVER['DOCUMENT_ROOT]
Notice: Undefined index: DOCUMENT_ROOT
because i cannot get any value from $_SERVER['DOCUMENT_ROOT]

is there any changes to be made in php.ini if yes then what they are?
so anyone help me

thanks n with regards
CN
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

How is php installed? As standalone/cli, cgi or as webserver module?
Which webserver do you use? Apache, IIS, ... ?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Have a read through this thread to see if there is anything that can help.

Also, try searching these boards for the terms 'undefined index DOCUMENT_ROOT' using the match all terms selection. There are a lot of posts about this.
User avatar
ronverdonk
Forum Commoner
Posts: 34
Joined: Sat Jun 10, 2006 7:06 am
Location: Netherlands

Bypass

Post by ronverdonk »

Found the following entry in the "Predefined variables" chapter at php.net. I tested it and it works.
You could use this instead of the golbal DOCUMENT_ROOT.
I was unable to convince my hosting company to change their installation of PHP and therefore had to find my own way to computer $_SERVER["DOCUMENT_ROOT"]. I eventually settled on the following, which is a combination of earlier notes (with some typos corrected):

Code: Select all

<?php
if ( ! isset($_SERVER['DOCUMENT_ROOT'] ) )
  $_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(
   $_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF']) ) );
?>
czarnick
Forum Newbie
Posts: 4
Joined: Sun Jul 30, 2006 1:44 pm

Post by czarnick »

i installed PHP Version 5.1.4 through window installer in windows 2000 advanced server and running on IIS Server
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

czarnick wrote:i installed PHP Version 5.1.4 through window installer in windows 2000 advanced server and running on IIS Server
Not to sound too confused, but what does this mean?
czarnick
Forum Newbie
Posts: 4
Joined: Sun Jul 30, 2006 1:44 pm

Post by czarnick »

hi everah

actually im answering to volka
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Ah, OK.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

document_root is an apache directive/variable and is not provided by iis.
So you probably have to stick with the workaround ronverdonk posted - if you really need document_root....
Post Reply