PHP - how can i get list of all headers
I use a php proxy to bypass JS cross domain issue. I want to pass some of 开发者_StackOverflow社区the headers from the client to the destination server.
How can i receive a list of all headers?
PHP has a built in function called get_headers() which you should be able to make use of.
You can access the request headers by calling getallheaders
.
Would not do that via PHP. See if this is suitable for you, if you use apache2: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
getallheaders() and apache_request_headers() don't seem to work on my server.. I'm assuming it's because its only available "under FastCGI" or "when PHP was installed as an Apache module." (according to http://www.php.net/manual/en/function.apache-request-headers.php)
However, a comment by jrabbit on the same page details a replacement function which seems to work for me:
<?php
if (!function_exists('apache_request_headers')) {
eval('
function apache_request_headers() {
foreach($_SERVER as $key=>$value) {
if (substr($key,0,5)=="HTTP_") {
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
$out[$key]=$value;
}
}
return $out;
}
');
}
?>
User limalopex.eisfux.de has another implementation on the same page which I have not tested.
精彩评论