php getallheaders使用注意事項

libmw發表於2014-06-18

This function is an alias for apache_request_headers(). Please read the apache_request_headers() documentation for more information on how this function works.

 

so if you want to use this function in any platform,you should detect if it is exists:

if (!function_exists('getallheaders'))
{
    function getallheaders()
    {
        $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;
    }
}

  

相關文章