I have some custom header, and it's not visible in $_SERVER
, but it visible with help apache_request_headers()
.
And such problem existing only in one Windows based Apache version (OpenServer). On Mac and Linux Apache pass all headers to php, and I can see it in $_SERVER
variable... maybe there is some restriction for windows? or is there any settings in apache.conf which can activate passing all header to mod_php?
When PHP is running as a Apache module on Windows, you won't see all headers on $_SERVER autoglobal array.
You have to retrieve them with apache_request_headers(). You could use some code to obtain cross platform deployment:
function GetHeader($myheader) {
if (isset($_SERVER[$myheader])) {
return $_SERVER[$myheader];
} else {
$headers = apache_request_headers();
if (isset($headers[$myheader])) {
return $headers[$myheader];
}
}
return '';
}
If you PHP is newer enough, you could also try getallheaders().
From PHP documentation: http://php.net/manual/en/reserved.variables.server.php
On the comments, notice that:
On Windows IIS 7 you must use $_SERVER['LOCAL_ADDR'] rather than $_SERVER['SERVER_ADDR'] to get the server's IP address.
It seems that some variable names are different in windows, so you'll have to find them out. If you have a close look at the documentation comments there are a few workarounds for some of them
php $_SERVER
is weired better option is to use apache_request_headers()
But if you want to still use $_SERVER
add HTTP_
and replace all -
to _
and the last thing to remember if the request header has _
than it will not be parsed at all (lost)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.