据我所知,apache_request_headers()
提供与$_SERVER
相同的信息,但密钥略有不同。为什么有人会使用apache_request_headers()
而不只是从$_SERVER
获取此信息?我在Centos上使用Apache运行PHP 5.3.18。谢谢
EDIT。来自$_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
答案 0 :(得分:4)
apache_request_headers
不是(完全)可移植的,$_SERVER
并不完整。最明确的是$_SERVER
永远不会包含任何Authorization
标头,无论PHP是否可以在内部处理其值。
自5.4.0以来,apache_request_headers
被修补以显示CGI部署中的所有标头。
答案 1 :(得分:3)
因为apache_request_headers()返回当前请求中所有HTTP标头的关联数组,其中$_SERVER提供的内容超过
答案 2 :(得分:3)
我猜这个函数只适用于Apache。但这只是一个疯狂的猜测
此外我猜这个函数会返回所有标题,我认为$ _SERVER包含一组预定义的标题