Not all headers are available in $ _SERVER [PHP]

I have my own custom header and it does not display in $_SERVER , but it displays using apache_request_headers() .

And such a problem exists in only one version of Apache based on Windows (OpenServer). On Mac and Linux, Apache passes all the headers to php, and I see this in the $_SERVER ... maybe there is some kind of restriction for windows? or are there any settings in apache.conf that can activate the transfer of the entire header to mod_php?

+4
source share
2 answers

When PHP works as an Apache module on Windows, you will not see all the headers in the autoglobal $ _SERVER array.

You should get them using apache_request_headers (). You can use some code to deploy a cross platform:

 function GetHeader($myheader) { if (isset($_SERVER[$myheader])) { return $_SERVER[$myheader]; } else { $headers = apache_request_headers(); if (isset($headers[$myheader])) { return $headers[$myheader]; } } return ''; } 

If PHP is even newer, you can also try getallheaders ().

http://php.net/manual/en/function.getallheaders.php

+4
source

From the PHP documentation: http://php.net/manual/en/reserved.variables.server.php

In the comments, note that:

On Windows IIS 7, you must use $ _SERVER ['LOCAL_ADDR'] instead of $ _SERVER ['SERVER_ADDR'] to get the IP address of the server.

It seems that some variable names differ in windows, so you have to find them. If you carefully review the documentation comments, some of them bypass some of them.

0
source

Source: https://habr.com/ru/post/1468933/


All Articles