getallheaders()
Available in PHP-FPM
Web applications typically deal with headers a lot. Request headers need to be parsed, because they contain information about which languages, encodings, or content types the client would like to receive. Authentication tokens are also usually sent as a header, and the session cookie that the client sends back to the server is technically also a header.
In former times when PHP was mostly run as an Apache module, the
function getallheaders()
could be used to retrieve all
headers the client had sent. Even though PHP does a fair bit of
automated header parsing, sometimes you just have to look into what
the client had originally sent.
Unfortunately, this useful function was originally only available
when installing PHP as an Apache module, or running it as an NSAPI
module. As of PHP 5.4, getallheaders()
also became
available under FastCGI, and PHP 5.5.7 also made it available when
PHP was run at the command line. Before that, testing code with
calls to getallheaders()
at the command line required
some ugly hacks.
As of PHP 7.3, getallheaders()
is also available
when using PHP-FPM. Since this is the preferred way of running PHP
in production these days: enjoy parsing request headers!