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.

返回值

An associative array of all the HTTP headers in the current request, orFALSE on failure. 

 

getallheaders() example


[php] copy
  1. <?php  
  2.   
  3. ) {  
  4. ;  
  5. }  
  6.   
  7. ?>   

不过这个函数只能在apache环境下使用,iis或者nginx并不支持,可以通过自定义函数实现

[php] copy
  1. <?php   
  2. ))   
  3. {  
  4. ()   
  5.     {  
  6. )   
  7.        {  
  8. )   
  9.            {  
  10. ;  
  11.            }  
  12.        }  
  13. ;  
  14.     }  
  15. }</span>   
  16. ?>   


好了,看看都打印出了啥吧

[php] copy
  1. <?php  
  2. ());  


获得结果:

[html] copy
  1. Array  
  2. (  
  3.  */*  
  4.  zh-cn  
  5.  gzip, deflate  
  6.  Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)  
  7.  localhost  
  8.  Keep-Alive  

相关文章:

  • 2021-08-12
  • 2022-12-23
  • 2021-10-17
  • 2021-07-05
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
猜你喜欢
  • 2021-07-14
  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案