Is it possible to get the http headers of the current request with PHP? I am not using Apache as the web-server, but using nginx.
I tried using getallheaders()
but I am getting Call to undefined function getallheaders()
.
Is it possible to get the http headers of the current request with PHP? I am not using Apache as the web-server, but using nginx.
I tried using getallheaders()
but I am getting Call to undefined function getallheaders()
.
You can upgrade your server to PHP 5.4 thereby giving you access to getallheaders() via fastcgi or simply parse what you need out of $_SERVER with a
foreach
loop and a little regex.Taken from the documentation someone wrote a comment...
This should work:
This issue was finally addressed in PHP 7.3.0, check release notes.
Combined getallheaders() + apache_request_headers() for nginx
Improved @Layke his function, making it a bit more secure to use it:
(wished I could just add this as a comment to his answer but still building on that reputation thingy -- one of my first replies)