在PHP中getallheaders可以直接获取到header头信息,但getallheaders在nginx环境中无法使用,所以在nginx就需要用其他的方法了。
分享一个我的站长站自己的编写的函数,代码如下:
1 2 3 4 5 6 7 8 9 | function NginxGetAllHeaders(){ //获取请求头 $headers = []; foreach ( $_SERVER as $name => $value ){ if ( substr ( $name , 0, 5) == 'HTTP_' ){ $headers [ str_replace ( ' ' , '-' , ucwords( strtolower ( str_replace ( '_' , ' ' , substr ( $name , 5)))))] = $value ; } } return $headers ; } |