php getsiteurl()函数
程序员文章站
2023-11-26 12:52:58
复制代码 代码如下:function getsiteurl() { global $_sconfig; if(empty($_sconfig['siteallurl']))...
复制代码 代码如下:
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;
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; //定义全局变量$_sconfig($_sconfig其实是个数组var,在common.php中有定义)
if(empty($_sconfig['siteallurl'])) //判断$_sconfig['siteallurl']变量是否为空
$uri = $_server['request_uri']?$_server['request_uri']:($_server['php_self']?$_server['php_self']:$_server['script_name']);
//将$_server['request_uri'];$_server['php_self'];$_server['script_name']通过三目运算后把结果给$url
//$_server也是数组,你可以打印一下,就知道干吗用的了.这里只涉及到三个数组元素
//$_server['request_uri']; //request_uri:/mysite/->站点目录?
//$_server['php_self']; //php_self:/mysite/index.php->当前正在执行脚本的文件名
//$_server['script_name']; //script_name:/mysite/index.php->包含当前脚本的路径