DOCUMENT_ROOT in Windows Server

DOCUMENT_ROOT in Windows Server

The $_SERVER['DOCUMENT_ROOT'] by default isn't available in 
Windows Server, copy the code below to the beginning of your 
PHP application to use the $_SERVER['DOCUMENT_ROOT'] variable.

// let's make sure the $_SERVER['DOCUMENT_ROOT'] variable is set
if(!isset($_SERVER['DOCUMENT_ROOT'])){ if(isset($_SERVER['SCRIPT_FILENAME'])){
$_SERVER['
DOCUMENT_ROOT'] =
str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])));
}; };
if(!
isset($_SERVER['
DOCUMENT_ROOT'])){ if(isset($_SERVER['PATH_TRANSLATED'])){
$_SERVER['
DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
}; };
//
$_SERVER['DOCUMENT_ROOT'] is now set - you can use it as usual...

Add Feedback