php $_SERVER['REQUEST_URI'] 和 $_GET['q'] 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4730798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what is the difference between $_SERVER['REQUEST_URI'] and $_GET['q']?
提问by user550265
what is the difference between $_SERVER['REQUEST_URI']
and $_GET['q']
(which is used in Drupal)?
$_SERVER['REQUEST_URI']
和$_GET['q']
(在 Drupal 中使用)有什么区别?
回答by Decent Dabbler
Given this example url:
鉴于此示例网址:
http://www.example.com/some-dir/yourpage.php?q=bogus&n=10
http://www.example.com/some-dir/yourpage.php?q=bogus&n=10
$_SERVER['REQUEST_URI']
will give you:
$_SERVER['REQUEST_URI']
会给你:
/some-dir/yourpage.php?q=bogus&n=10
/some-dir/yourpage.php?q=bogus&n=10
Whereas $_GET['q']
will give you:
而$_GET['q']
会给你:
bogus
bogus
In other words, $_SERVER['REQUEST_URI']
will hold the full request path including the querystring. And $_GET['q']
will give you the value of parameter q
in the querystring.
换句话说,$_SERVER['REQUEST_URI']
将保存包括querystring在内的完整请求路径。而且$_GET['q']
会给你参数的值q
在查询字符串。
回答by mpdonadio
In the context of Drupal, the difference will depend whether clean URLs are on or not.
在 Drupal 的上下文中,区别将取决于是否启用了干净的 URL。
With them off, $_SERVER['REQUEST_URI']
will have the full path of the page as called w/ /index.php
, while $_GET["q"]
will just have what is assigned to q
.
关闭它们后,$_SERVER['REQUEST_URI']
页面的完整路径将被称为 w/ /index.php
,而$_GET["q"]
只会拥有分配给q
.
With them on, they will be nearly identical w/o other arguments, but $_GET["q"]
will be missing the leading /
. Take a look towards the end of the default .htaccess to see what is going on. They will also differ if additional arguments are passed into the page, eg when a pager is active.
启用它们后,它们将几乎相同,$_GET["q"]
没有其他参数,但会缺少前导/
. 查看默认 .htaccess 的末尾,看看发生了什么。如果将附加参数传递到页面中,例如当寻呼机处于活动状态时,它们也会有所不同。
回答by mario
The PHP manual explains both quite well:
PHP手册很好地解释了两者:
http://php.net/manual/en/reserved.variables.server.php# REQUEST_URI
http://php.net/manual/en/reserved.variables.server.php# REQUEST_URI
http://php.net/manual/en/reserved.variables.get.php# for the $_GET["q"] variable
http://php.net/manual/en/reserved.variables.get.php# 用于 $_GET["q"] 变量