PHP手册提供了现成的函数:
(PHP 4, PHP 5)
Fetch all HTTP request headers
说明
array
getallheaders ( void )
Fetches all HTTP headers from the current request.
apache_request_headers() documentation for more information on how this function works.
getallheaders() example
- <?php
- ) {
- ;
- }
- ?>
不过这个函数只能在apache环境下使用,iis或者nginx并不支持,可以通过自定义函数实现
- <?php
- ))
- {
- ()
- {
- )
- {
- )
- {
- ;
- }
- }
- ;
- }
- }</span>
- ?>
好了,看看都打印出了啥吧
- <?php
- ());
获得结果:
- Array
- (
- */*
- zh-cn
- gzip, deflate
- Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)
- localhost
- Keep-Alive
- )