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()
.
Receiving the request header, the web server will send an HTTP response header back to the client. Read any request header: It can be achieved by using getallheaders() function. Example 2: It can be achieved by using apache_request_headers() function.
The get_headers() function in PHP is used to fetch all the headers sent by the server in the response of an HTTP request.
you can use getallheaders() to get an array of all HTTP headers sent. Show activity on this post. Every HTTP request header field is in $_SERVER (except Cookie ) and the key begins with HTTP_ . If you're using Apache, you can also try apache_request_headers .
Taken from the documentation someone wrote a comment...
if (!function_exists('getallheaders')) { function getallheaders() { $headers = array (); foreach ($_SERVER as $name => $value) { if (substr($name, 0, 5) == 'HTTP_') { $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; } } return $headers; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With