Home  >  Article  >  Backend Development  >  php getsiteurl() function_PHP tutorial

php getsiteurl() function_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:44:451002browse

Copy code The code is as follows:
function getsiteurl()
{
global $_SCONFIG;

if(empty ($_SCONFIG['siteallurl']))
{
$uri = $_SERVER['REQUEST_URI']?$_SERVER['REQUEST_URI']:($_SERVER['PHP_SELF']?$_SERVER['PHP_SELF ']:$_SERVER['SCRIPT_NAME']);
return shtmlspecialchars('http://'.$_SERVER['HTTP_HOST'].substr($uri, 0, strrpos($uri, '/')+ 1));
}
else
{
return $_SCONFIG['siteallurl'];
}
}

global $_SCONFIG; / /Define global variable $_SCONFIG ($_SCONFIG is actually an array var, defined in common.php)

if(empty($_SCONFIG['siteallurl'])) //Judge $_SCONFIG['siteallurl' ] Is the variable empty

$uri = $_SERVER['REQUEST_URI']?$_SERVER['REQUEST_URI']:($_SERVER['PHP_SELF']?$_SERVER['PHP_SELF']:$_SERVER[ 'SCRIPT_NAME']);

//Put $_SERVER['REQUEST_URI'];$_SERVER['PHP_SELF'];$_SERVER['SCRIPT_NAME'] through ternary operation and give the result to $url

//$_SERVER is also an array, you can print it and you will know what it is used for. Only three array elements are involved here

//$_SERVER['REQUEST_URI']; //REQUEST_URI :/mysite/->Site directory?

//$_SERVER['PHP_SELF']; //PHP_SELF:/mysite/index.php->The file name of the currently executing script

//$_SERVER['SCRIPT_NAME']; //SCRIPT_NAME:/mysite/index.php->Path containing the current script

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320518.htmlTechArticleCopy the code The code is as follows: function getsiteurl() { global $_SCONFIG; if(empty($_SCONFIG['siteallurl' ])) { $uri = $_SERVER['REQUEST_URI']?$_SERVER['REQUEST_URI']:($_SERVER['PHP_SELF...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn