7

据我所知,apache_request_headers()提供与 相同的信息$_SERVER,但键略有不同。为什么有人应该使用apache_request_headers()而不只是从中获取这些信息$_SERVER?我在 Centos 上使用 Apache 运行 PHP 5.3.18。谢谢

编辑。$_SERVER来自和的相同数据apache_request_headers()

Jun  2 08:50:53 localhost httpd: HTTP_HOST: www.badobe.com
Jun  2 08:50:53 localhost httpd: Host: www.badobe.com
Jun  2 08:50:53 localhost httpd: HTTP_USER_AGENT: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0
Jun  2 08:50:53 localhost httpd: User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0
Jun  2 08:50:53 localhost httpd: HTTP_ACCEPT: */*
Jun  2 08:50:53 localhost httpd: Accept: */*
Jun  2 08:50:53 localhost httpd: HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.5
Jun  2 08:50:53 localhost httpd: Accept-Language: en-US,en;q=0.5
Jun  2 08:50:53 localhost httpd: HTTP_ACCEPT_ENCODING: gzip, deflate
Jun  2 08:50:53 localhost httpd: Accept-Encoding: gzip, deflate
Jun  2 08:50:53 localhost httpd: HTTP_REFERER: http://www.badobe.com/demo/administrator/index.php?cid=3
Jun  2 08:50:53 localhost httpd: Referer: http://www.badobe.com/demo/administrator/index.php?cid=3
Jun  2 08:50:53 localhost httpd: HTTP_COOKIE: PHPSESSID=feg3ecd4rsefvd03mgg6qear21
Jun  2 08:50:53 localhost httpd: Cookie: PHPSESSID=feg3ecd4rsefvd03mgg6qear21
Jun  2 08:50:53 localhost httpd: HTTP_CONNECTION: keep-alive
Jun  2 08:50:53 localhost httpd: Connection: keep-alive
Jun  2 08:50:53 localhost httpd: HTTP_IF_MODIFIED_SINCE: Sun, 02 Jun 2013 15:48:42 GMT
Jun  2 08:50:53 localhost httpd: If-Modified-Since: Sun, 02 Jun 2013 15:48:42 GMT
Jun  2 08:50:53 localhost httpd: HTTP_CACHE_CONTROL: max-age=0
Jun  2 08:50:53 localhost httpd: Cache-Control: max-age=0
4

3 回答 3

6

因为apache_request_headers()返回当前请求中所有 HTTP 标头的关联数组,其中$_SERVER提供的远不止这些

  • 标题详细信息
  • 路径详情
  • 脚本位置
于 2013-06-02T16:00:13.003 回答
5

我猜这个函数只适用于 Apache。但这只是一个疯狂的猜测

此外,我猜该函数返回所有标头,我认为 $_SERVER 包含一组预定义的标头

于 2013-06-02T16:06:14.227 回答
5

apache_request_headers不是(完全)可移植的,$_SERVER也不是完全完整的。尤其是$_SERVER从不包含任何Authorization标题,无论 PHP 是否可以在内部处理它的值。

自从 5.4.0apache_request_headers被修补后,也可以显示 CGI 部署中的所有标头。

于 2015-06-23T14:14:37.243 回答