note 73964 deleted from function.apache-request-headers by danbrown
| From: | danbrown@php.net | Date: | Mon, 08 Jun 2009 18:49:20 +0000 |
| Subject: | note 73964 deleted from function.apache-request-headers by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156484@lists.php.net to get a copy of this message | ||
Note Submitter: tehjosh at gamingg dot net
----
I wrote a function similar to jrabbit's, except that mine creates a custom function rather than
redefining the original.
<?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;
}
?>
Also, eval() is not necessary to define a function that is within an if block, as is done in
jrabbit's code, because PHP will only read the function if it passes the if condition.