...

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



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


<?php
$HttpStatus = $_SERVER["REDIRECT_STATUS"] ;
statusFunc($HttpStatus);
?>


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

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

apache_request_headers()


<?php
$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:


<?php
function parseRequestHeaders() {
$headers = array();
foreach($_SERVER as $key => $value) {
if (substr($key, 0, 5) <> 'HTTP_') {
continue;
}
$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

Fou-Lu
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum