Home > Article > Backend Development > php gets http headers
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.