yousafsyed / php5rp

Automatically exported from code.google.com/p/php5rp
0 stars 0 forks source link

apache_request_headers not available in all php configs #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Not all PHP5 configs support apache_request_headers. For one, PHP may not be 
running on Apache. 
Or it may be configured in such a way so as not to allow access to that 
function for security 
reasons.

Thus, when that function is not available, php5rp should try its best to 
re-construct the request 
headers from PHP globals such as $_COOKIE and others.

Original issue reported on code.google.com by Alexei.Svitkine@gmail.com on 17 Aug 2008 at 6:59

GoogleCodeExporter commented 8 years ago
Here is an alternate way to retrieve those headers, as suggested by tehjosh who 
left
this comment in the PHP documentation
(http://ca2.php.net/manual/en/function.apache-request-headers.php#73964):

<?php
function request_headers()
{
    if(function_exists("apache_request_headers")) // If apache_request_headers()
exists...
    {
        if($headers = apache_request_headers()) // And works...
        {
            return $headers; // Use it
        }
    }

    $headers = array();

    foreach(array_keys($_SERVER) as $skey)
    {
        if(substr($skey, 0, 5) == "HTTP_")
        {
            $headername = str_replace(" ", "-", ucwords(strtolower(str_replace("_", "
", substr($skey, 0, 5)))));
            $headers[$headername] = $_SERVER[$skey];
        }
    }

    return $headers;
}
?>

Original comment by read.ish...@gmail.com on 13 Mar 2009 at 8:42

GoogleCodeExporter commented 8 years ago
Here is another similar (almost the same) article about patching servers that 
doesn't 
have "apache_request_headers()" available (due to being running PHP as FastCGI 
instead 
of as an Apache module).

http://www.electrictoolbox.com/php-get-headers-sent-from-browser/

Original comment by mani...@gmail.com on 10 May 2010 at 7:42