Another code snippet for you all. I like to use the DOCUMENT_ROOT variable in my scripts, it is as if nothing else is ever quite as useful. Unfortunately here at redfox the variable is currently not set, which can be frustraiting.
Stick this tiny bit of code so that it is one of the first things parsed, and it will set the variable for you, regardless of where the file resides, so you can use it again throughout your program.
There might be occasions where this will break down, but so far I don't know of any.
PHP Code:/**
* On Some PHP installations the Document Root variable is not set, here we
* quickly check, and if it is not already, set the variable.
*/
if( !isset($_SERVER['DOCUMENT_ROOT']) ) {
$_SERVER['DOCUMENT_ROOT'] = str_replace($_SERVER['SCRIPT_NAME'],'',
str_replace('\\','/',$_SERVER['SCRIPT_FILENAME']));
}


Reply With Quote

Bookmarks