: This article mainly introduces the problem that PHPgetallheaders cannot obtain the custom headers. For more information about PHP tutorials, see. A custom http header is added to the client request. the request is as follows:
Custom http request header
var_dump(getallheaders);
At first, the getallheaders parameter was obtained, but it was found that it could not be obtained on the nginx deployed server. it was very strange that the getallheaders function only supported the apache server. Then find the compatible method:
if (!function_exists('getallheaders')) {function getallheaders() {$headers = array();foreach ($_SERVER as $name => $value) {if (substr($name, 0, 5) == 'HTTP_') {$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;}}return $headers;}}var_dump(getallheaders());
In fact, this method finds the attribute starting with HTTP _ in the $ _ SERVER variable and replaces the attribute with a string. In the $ _ SERVER variable, HTTP_USER_ID is actually the User-Id defined above:
$ _ SERVER variable in php
In addition, for custom Http headers, note the naming rules of headers. do not use underscores to name them. Otherwise, the headers cannot be read on the nginx server. when searching for naming rules, we have mentioned that custom attributes start with X. Later, I checked some information and found that later http protocol is not recommended.
The above is a description of the problem that PHP getallheaders cannot obtain the custom header (headers). I hope it will help you!
The above introduces the problem that PHP getallheaders cannot get the custom header headers, including some content, and hope to help those who are interested in PHP tutorials.