Home > Backend Development > PHP Tutorial > php gets http headers

php gets http headers

高洛峰
Release: 2016-10-20 14:20:46
Original
1578 people have browsed it

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; 
 }
Copy after login

can be used on any WEB server.


Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template