PHP DOCUMENT_ROOT in Windows Servers
Being a Mac user somehow makes you tend to forget others in Windows world. Recently, one of my app failed to redirect my script to proper url simply because it was not be able to detect $_SERVER['DOCUMENT_ROOT'] variable. I thot I have already fixed this, but unfortunately it is not or my assumptions was wrong. So, being a lazy developer, Googling surely help me and found this solution:
// 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...
Thanks to Fyneworks for the article – http://fyneworks.blogspot.com/2007/08/php-documentroot-in-iis-windows-servers.html