download this file: func.globals.php view text/plain: func.globals.php file encoding: UTF-8 [goback]
<?php
##
## this file name is 'func.globals.php'
##
## globlas functions
##
## [author]
## - Chilbong Kim<san2(at)linuxchannel.net>
##
## [changes]
## - 2013.02.25 : bug fixed $_SERVER['_URI']
## - 2005.09.14 : bug fixed $_SERVER['_URI']
## - 2005.02.28 : add $_SERVER['_BUI']
## - 2003.07.02 : realuri() bug fixed
## - 2003.03.17 : realuri() bug fixed
## - 2003.03.06 : new build
##
## [references]
##
## [usage]
##
## [example]
##
## if you using the PHP/4.0.x
## http://www.php.net/ChangeLog-4.php
##
function _globals()
{
global $_SERVER; // add user vars for 4.0.x
if(preg_match('/^4\.0/',PHP_VERSION))
{
$GLOBALS['_SERVER'] = array_merge($GLOBALS['HTTP_SERVER_VARS'],$_SERVER);
$GLOBALS['_GET'] = $GLOBALS['HTTP_GET_VARS'];
$GLOBALS['_POST'] = $GLOBALS['HTTP_POST_VARS'];
$GLOBALS['_COOKIE'] = $GLOBALS['HTTP_COOKIE_VARS'];
$GLOBALS['_SESSION'] = $GLOBALS['HTTP_SESSION_VARS'];
$GLOBALS['_ENV'] = $GLOBALS['HTTP_ENV_VARS'];
$GLOBALS['_FILES'] = $GLOBALS['HTTP_POST_FILES']; // ???
$GLOBALS['_REQUEST'] = array_merge($_GET,$_COOKIE);
}
}
## this alias
##
function _global()
{
return _globals();
}
## get $_SERVER['_URI'] and $_SERVER['_PHP_SELF'] (for includes)
##
function realuri($_OPWD)
{
global $_SERVER; // add user vars for 4.0.x
if(!$_SERVER) _globals(); // re-check PHP version
$GLOBALS['_SERVER']['_PWD'] = $_PWD = realpath($_OPWD); // it's override
$GLOBALS['_SERVER']['_PHP_SELF'] = $_SERVER['SCRIPT_NAME'];
$GLOBALS['_SERVER']['_SURI'] = preg_replace(';index\.(?:php|php4)$;i','',$_SERVER['SCRIPT_NAME']);
if($_SERVER['_URI']) return; // it's not override
## for system account user
##
if(preg_match(';^/~;',$_SERVER['REQUEST_URI']))
{
$_S['_SNAME'] = realpath($_SERVER['SCRIPT_FILENAME']);
$_S['_FNAME'] = preg_replace(';^/~[^/]+;','',$_SERVER['SCRIPT_NAME']);
$_S['_UURI'] = str_replace($_S['_FNAME'],'',$_SERVER['SCRIPT_NAME']);
$_S['_DOCUMENT_ROOT'] = str_replace($_S['_FNAME'],'',$_S['_SNAME']);
$_S['_DOCUMENT_PATH'] = str_replace($_S['_DOCUMENT_ROOT'],'',$_PWD);
$_URI = $_S['_UURI'] . $_S['_DOCUMENT_PATH'];
}
else
{
$_SERVER['DOCUMENT_ROOT'] = preg_replace(';/+$;','',$_SERVER['DOCUMENT_ROOT']); // rtrim(/)
if(preg_match(';^'.$_SERVER['DOCUMENT_ROOT'].';',$_PWD))
{
$_URI = str_replace($_SERVER['DOCUMENT_ROOT'],'',$_PWD);
}
else if(preg_match(';^'.$_PWD.';',$_OPWD)) // symbolic link match, san2@2013.02.25
{
$_URI = preg_replace(';^'.$_PWD.';','',$_OPWD);
$_URI = $_URI ? dirname(realpath($_URI)) : '';
}
else // may be
{
$_URI = str_replace($_SERVER['DOCUMENT_ROOT'],'',$_SERVER['SCRIPT_FILENAME']);
$_URI = dirname($_URI);
}
}
## patch san2@2005.09.14
##
$GLOBALS['_SERVER']['_URI'] = preg_replace(array(';^/+;',';^/$;'),array('/',''),$_URI); // it's not override
$GLOBALS['_SERVER']['_BUI'] = dirname($_SERVER['SCRIPT_NAME']); // base uri
}
?>