`

php$_SERVER[’PHP_SELF’], $_SERVER['REQUEST_URI'], and $_SERVER[’SCRIPT_NAME’]区别

阅读更多
$_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在用法上是非常相似的,他们返回的都是与当前正在使用的页面地址有关的信息,这里列出一些相关的例子,帮助确定哪些是在你的脚本最适合的。
$_SERVER[’PHP_SELF’]http://www.fenge8.cn/example/ — – — /example/index.php
http://www.fenge8.cn/example/index.php — – — /example/index.php
http://www.fenge8.cn/example/index.php?a=test — – — /example/index.php
http://www.fenge8.cn/example/index.php/dir/test — – — /dir/test
当我们使用$_SERVER['PHP_SELF']的时候,无论访问的URL地址是否有index.php,它都会自动的返回 index.php.但是如果在文件名后面再加斜线的话,就会把后面所有的内容都返回在$_SERVER['PHP_SELF']。
$_SERVER['REQUEST_URI']
http://www.fenge8.cn/example/ — – — /
http://www.fenge8.cn/example/index.php — – — /example/index.php
http://www.fenge8.cn/example/index.php?a=test — – — /example/index.php?a=test
http://www.fenge8.cn/example/index.php/dir/test — – — /example/index.php/dir/test
$_SERVER['REQUEST_URI']返回的是我们在URL里写的精确的地址,如果URL只写到”/”,就返回 “/”
$_SERVER['SCRIPT_NAME']
http://www.fenge8.cn/example/ — – — /example/index.php
http://www.fenge8.cn/example/index.php — – — /example/index.php
http://www.fenge8.cn/example/index.php — – — /example/index.php
http://www.fenge8.cn/example/index.php/dir/test — – — /example/index.php
在所有的返回中都是当前的文件名/example/index.php
分享到:
评论

相关推荐

    PHP $_SERVER详解

    $_SERVER[‘REMOTE_HOST’] //当前用户主机名 $_SERVER[‘REQUEST_URI’] //URL$_SERVER[‘REMOTE_PORT’] //端口。 $_SERVER[‘SERVER_NAME’] //服务器主机的名称。 $_SERVER[‘PHP_SELF’]//正在执行脚本的...

    PHP_SELF,SCRIPT_NAME,REQUEST_URI区别

    $_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER[‘REQUEST_URI’] 在用法上是非常相似的,他们返回的都是与当前正在使用的页面地址有关的信息,这里列出一些相关的例子,帮助确定哪些是在你的脚本最适合的。...

    php getsiteurl()函数

    复制代码 代码如下:function getsiteurl() { global $_SCONFIG;...$_SERVER[‘PHP_SELF’]:$_SERVER[‘SCRIPT_NAME’]); return shtmlspecialchars(‘http://’.$_SERVER[‘HTTP_HOST’].substr($uri, 0, strrpos($uri,

    PHP 采集程序 常用函数

    empty($_SERVER[“REQUEST_URI”])){ $scriptName = $_SERVER[“REQUEST_URI”]; $nowurl = $scriptName; }else{ $scriptName = $_SERVER[“PHP_SELF”]; if(empty($_SERVER[“QUERY_STRING”])) $nowurl = $script...

    PHP 采集程序中常用的函数

    empty($_SERVER[”REQUEST_URI”])) { $scriptName = $_SERVER[”REQUEST_URI”]; $nowurl = $scriptName; } else { $scriptName = $_SERVER[”PHP_SELF”]; if(empty($_SERVER[”QUERY_STRING”])) $nowurl = $...

    PHP获取当前url路径的函数及服务器变量QUERY_STRING、REQUEST_URI

    PHP获取当前url路径的函数及服务器变量:QUERY_STRING、REQUEST_URI、SCRIPT_NAME、PHP_SELF

    php获取当前网址url并替换参数或网址的方法

    empty($_SERVER[“REQUEST_URI”])) { $scriptName = $_SERVER[“REQUEST_URI”]; $nowurl = $scriptName; } else { $scriptName = $_SERVER[“PHP_SELF”]; if(empty($_SERVER[“QUERY_STRING”])) { $nowurl = $...

    DX1.5 手机正式版

    $_SERVER['SCRIPT_NAME'] : $_SERVER['PHP_SELF']); //当前脚本 比如forum $_G['basescript'] = CURSCRIPT; //站点地址 $_G['siteurl'] = htmlspecialchars(‘http://’.$_SERVER['HTTP_HOST'].preg_replace(“/\/+...

    php获得当前的脚本网址

    //获得当前的脚本网址 function GetCurUrl(){  if(!empty($_SERVER[“REQUEST_... $scriptName = $_SERVER[“PHP_SELF”];  if(empty($_SERVER[“QUERY_STRING”])) $nowurl = $scriptName;  else $now

    PHP获取当前URL路径的处理方法(适用于多条件筛选列表)

    * $_SERVER["REQUEST_URI"] 访问此页面所需的URI * $_SERVER["SCRIPT_NAME"] 包含当前脚本的路径 * $_SERVER["PHP_SELF"] 当前正在执行脚本的文件名 * 适用于列表多条件筛选处理,如:价格,时间,类型等等 * @...

    [PHP]实用函数3

    empty($_server[“REQUEST_URI”])){ $scriptName = $_SERVER[“REQUEST_URI”]; $nowurl = $scriptName; }else{ $scriptName = $_SERVER[“PHP_SELF”]; if(empty($_SERVER[“QUERY_S

    google api php client

    $_SERVER['PHP_SELF']; $client->setRedirectUri($redirect_uri); ``` 1. In the script handling the redirect URI, exchange the authorization code for an access token: ```php if (isset($_GET['code']...

    ZendFramework中文文档

    14.5.3. Retrieving Validated Fields and other Reports 14.5.3.1. Querying if the input is valid 14.5.3.2. Getting Invalid, Missing, or Unknown Fields 14.5.3.3. Getting Valid Fields 14.5.4. Using ...

Global site tag (gtag.js) - Google Analytics