Welcome, guest | Sign In | My Account | Store | Cart

$_SERVER['DOCUMENT_ROOT'] has been known to be broken on some servers. This is a bit of logic to retrieve the document root more reliably.

PHP, 1 line
1
$docroot = realpath((getenv('DOCUMENT_ROOT') && ereg('^'.preg_quote(realpath(getenv('DOCUMENT_ROOT'))), realpath(__FILE__))) ? getenv('DOCUMENT_ROOT') : str_replace(dirname(@$_SERVER['PHP_SELF']), '', str_replace(DIRECTORY_SEPARATOR, '/', dirname(__FILE__))));
Created by Gui R on Thu, 25 Dec 2008 (MIT)
PHP recipes (51)
Gui R's recipes (3)

Required Modules

  • (none specified)

Other Information and Tasks