Get the http headers from current request in PHP

后端 未结 6 1853
梦谈多话
梦谈多话 2020-12-08 04:10

Is it possible to get the http headers of the current request with PHP? I am not using Apache as the web-server, but using nginx.

I tried using

6条回答
  •  既然无缘
    2020-12-08 04:42

    Taken from the documentation someone wrote a comment...

    if (!function_exists('getallheaders')) 
    { 
        function getallheaders() 
        { 
           $headers = array (); 
           foreach ($_SERVER as $name => $value) 
           { 
               if (substr($name, 0, 5) == 'HTTP_') 
               { 
                   $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; 
               } 
           } 
           return $headers; 
        } 
    } 
    

提交回复
热议问题