what is the difference between $_SERVER['REQUE

2019-01-13 18:31发布

what is the difference between $_SERVER['REQUEST_URI'] and $_GET['q'] (which is used in Drupal)?

标签: php drupal
3条回答
戒情不戒烟
2楼-- · 2019-01-13 18:40

Given this example url:

http://www.example.com/some-dir/yourpage.php?q=bogus&n=10

$_SERVER['REQUEST_URI'] will give you:

/some-dir/yourpage.php?q=bogus&n=10

Whereas $_GET['q'] will give you:

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.

查看更多
仙女界的扛把子
3楼-- · 2019-01-13 18:43

The PHP manual explains both quite well:

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

查看更多
戒情不戒烟
4楼-- · 2019-01-13 18:57

In the context of Drupal, the difference will depend whether clean URLs are on or not.

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.

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.

查看更多
登录 后发表回答