View Full Version : $_SERVER["REDIRECT_STATUS"] to get all headers

07-31-2012, 09:37 PM
Just want to know how to get status headers:


This would work and can I place in my init.php + would it work for a 403?

07-31-2012, 10:19 PM
Simple method (Works only with apache)


$headers = apache_request_headers();

foreach ($headers as $header => $value) {
echo "$header: $value <br />\n";
If you are not running PHP with apache, you could use:

function parseRequestHeaders() {
$headers = array();
foreach($_SERVER as $key => $value) {
if (substr($key, 0, 5) <> 'HTTP_') {
$header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
$headers[$header] = $value;
return $headers;

Source: http://stackoverflow.com/questions/541430/how-do-i-read-any-request-header-in-php

08-01-2012, 01:23 AM
You mean if you set up an error document handler for 404/403? Then yeah, if its forwarded you can find it under the REDIRECT_STATUS header.
Of course it wouldn't work by itself. If you trigger a 404 or 403 accessing a script, that would indicate that it doesn't exist or that it cannot be accessed through security. If that triggers a 403 without a custom error handler, then it would just present the 404/403 browser error.