PHP_SELF、 SCRIPT_NAME、 REQUEST_URI区别

PHP_SELF、 SCRIPT_NAME、 REQUEST_URI区别

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

$_SERVER[’PHP_SELF’]

  • http://www.yoursite.com/example/ — – — /example/index.php
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php?a=test — – — /example/index.php
  • http://www.yoursite.com/example/index.php/dir/test — – — /dir/test

当我们使用$_SERVER[‘PHP_SELF‘]的时候,无论访问的URL地址是否有index.php,它都会自动的返回 index.php.但是如果在文件名后面再加斜线的话,就会把后面所有的内容都返回在$_SERVER[‘PHP_SELF‘]。

$_SERVER[‘REQUEST_URI‘]

  • http://www.yoursite.com/example/ — – — /
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php?a=test — – — /example/index.php?a=test
  • http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php/dir/test

$_SERVER[‘REQUEST_URI‘]返回的是我们在URL里写的精确的地址,如果URL只写到”/”,就返回 “/”

$_SERVER[‘SCRIPT_NAME‘]

  • http://www.yoursite.com/example/ — – — /example/index.php
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php

在所有的返回中都是当前的文件名/example/index.php

时间: 2024-08-10 17:08:53

PHP_SELF、 SCRIPT_NAME、 REQUEST_URI区别的相关文章

详解 $_SERVER 函数中QUERY_STRING和REQUEST_URI区别

http://blog.sina.com.cn/s/blog_686999de0100jgda.html 实例: 1,http://localhost/aaa/ (打开aaa中的index.php)结果:$_SERVER['QUERY_STRING'] = "";$_SERVER['REQUEST_URI']  = "/aaa/";$_SERVER['SCRIPT_NAME']  = "/aaa/index.php";$_SERVER['PHP_

【转载】详解 $_SERVER 函数中QUERY_STRING和REQUEST_URI区别

实例: 1,http://localhost/aaa/ (打开aaa中的index.php)结果:$_SERVER['QUERY_STRING'] = "";$_SERVER['REQUEST_URI']  = "/aaa/";$_SERVER['SCRIPT_NAME']  = "/aaa/index.php";$_SERVER['PHP_SELF']     = "/aaa/index.php"; 2,http://loc

nginx uri和request_uri区别

$request_uri This variable is equal to the *original* request URI as received from the client including the args. It cannot be modified. Look at $uri for the post-rewrite/altered URI. Does not include host name. Example: "/foo/bar.php?arg=baz" 这

了解预定义变量$_SERVER

这一节主要内容是了解预定义变量$_SERVER的用法. $_SERVER 是一个包含了诸如头信息(header).路径(path).以及脚本位置(script locations)等等信息的数组.这个数组中的项目由 Web 服务器创建.不能保证每个服务器都提供全部项目:服务器可能会忽略一些,或者提供一些没有在这里列举出来的项目.这也就意味着大量的此类变量都会在? CGI 1.1 规范中说明,所以应该仔细研究一下. $HTTP_SERVER_VARS 包含着相同的信息,但它不是一个超全局变量. (

[李景山php]每天TP5-20170131|thinkphp5-Request.php-3

/**  * 获取当前URL 不含QUERY_STRING  * @access public  * @param string $url URL地址  * @return string  */ public function baseUrl($url = null) {     if (!is_null($url) && true !== $url) {         $this->baseUrl = $url;         return $this;     } elsei

PHP $_SERVER['PHP_SELF']、$_SERVER['SCRIPT_NAME'] 与 $_SERVER['REQUEST_URI'] 之间的区别

http://www.5idev.com/php/index.php/test/foo?username=hbolive $_SERVER['PHP_SELF'] 得到:/php/index.php/test/foo $_SERVER['SCRIPT_NAME'] 得到:/php/index.php $_SERVER['REQUEST_URI'] 得到:/php/index.php/test/foo?username=hbolive 从该例子可以看出: $_SERVER['PHP_SELF']

$_SERVER[PHP_SELF] - $_SERVER[SCRIPT_NAME] - $_SERVER['REQUEST_URI']的区别

$_SERVER[PHP_SELF],$_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI']在用法上是非常相似的,他们返回的都是与当前正在使用的页面地址有关的信息. $_SERVER[’PHP_SELF’] http://www.yoursite.com/example/ —– — /example/index.php http://www.yoursite.com/example/index.php —– — /example/index.php http

$_SERVER["SCRIPT_NAME"]、$_SERVER["PHP_SELF"]、$_SERVER["QUERY_STRING"]、$_SERVER["REQUEST_URI"]

1.$_SERVER["SCRIPT_NAME"] 说明:包含当前脚本的路径 2.$_SERVER["PHP_SELF"] 说明:当前正在执行脚本的文件名 3.$_SERVER["QUERY_STRING"] 说明:查询(query)的字符串 4.$_SERVER["REQUEST_URI"] 说明:访问此页面所需的URI 实例: 1.http://blog.snsgou.com/ (直接打开主页) 结果: $_SERVER[

__FILE__ $_SERVER['PHP_SELF'] $_SERVER['SCRIPT_NAME'] $_SERVER['SCRIPT_FILENAME'] 的区别

echo "<strong>"; echo "__FILE__:".__FILE__;echo "<br/>"; echo "PHP-SELF:".$_SERVER['PHP_SELF'];echo "<br/>"; echo "name:".$_SERVER['SCRIPT_NAME'];echo "<br/>"; e