Home  >  Article  >  Backend Development  >  php gets http headers

php gets http headers

高洛峰
高洛峰Original
2016-10-20 14:20:461543browse

getallheaders() can get all http headers, but it can only be used on the apache server.
Use $_SERVER to encapsulate a general function.

function emu_getallheaders() { 
    foreach ($_SERVER as $name => $value) 
    { 
        if (strncmp($name, 'HTTP_', 5) === 0) 
        { 
            $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); 
            $headers[$name] = $value; 
        } else if ($name == "CONTENT_TYPE") { 
            $headers["Content-Type"] = $value; 
        } else if ($name == "CONTENT_LENGTH") { 
            $headers["Content-Length"] = $value; 
        } 
    } 
    return $headers; 
 }

can be used on any WEB server.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php handles wsdlNext article:php handles wsdl