Here\'s a problem that I\'ve been running into lately - a misconfigured apache on a webhost. This means that all scripts that rely on $_SERVER[\'DOCUMENT_ROOT\']
Based on http://www.helicron.net/php/:
$localpath=getenv("SCRIPT_NAME");
$absolutepath=getenv("SCRIPT_FILENAME");
$_SERVER['DOCUMENT_ROOT']=substr($absolutepath,0,strpos($absolutepath,$localpath));
I had to change the basename/realpath trick because it returned an empty string on my host. Instead, I use SCRIPT_FILENAME. This probably won't work on IIS anymore (but the original scripts that used the $_SERVER variable probably wouldn't either).