Page 1 of 1

error while using server variables

Posted: Sun Jul 30, 2006 1:53 pm
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

Posted: Sun Jul 30, 2006 3:36 pm
by volka
How is php installed? As standalone/cli, cgi or as webserver module?
Which webserver do you use? Apache, IIS, ... ?

Posted: Sun Jul 30, 2006 3:50 pm
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.

Bypass

Posted: Sun Jul 30, 2006 5:37 pm
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']) ) );
?>

Posted: Sun Jul 30, 2006 10:32 pm
by czarnick
i installed PHP Version 5.1.4 through window installer in windows 2000 advanced server and running on IIS Server

Posted: Sun Jul 30, 2006 11:25 pm
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?

Posted: Mon Jul 31, 2006 12:25 am
by czarnick
hi everah

actually im answering to volka

Posted: Mon Jul 31, 2006 12:29 am
by RobertGonzalez
Ah, OK.

Posted: Mon Jul 31, 2006 6:57 am
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....