search
Homephp教程php手册php getsiteurl()函数

php getsiteurl()函数

Jun 13, 2016 pm 12:22 PM
functionglobalphpcodefunctioncopy

复制代码 代码如下:

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->包含当前脚本的路径
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version