Home > php教程 > php手册 > body text

php getsiteurl()函数

WBOY
Release: 2016-06-13 12:22:06
Original
876 people have browsed it

复制代码 代码如下:

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; //定义全局变量$_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->包含当前脚本的路径
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!