The custom HTTP headers were added at the time of the client request, and the request looks like this:
Custom HTTP request Headers
Var_dump (getallheaders);
It started with the getallheaders parameter, but found that it was not available on the Nginx deployed server, and it was very strange to see the PHP manual found that getallheaders this function only supports Apache servers. Then find a compatible method:
if (!function_exists (' getallheaders ')) {
function getallheaders () {
$headers = array ();
foreach ($_server as $name => $value) {
if (substr ($name, 0, 5) = = ' Http_ ') {
$headers [Str_replace ('], '-', UC Words (Strtolower (Str_replace (' _ ', ', substr ($name, 5)))] = $value;
}
}
return $headers;
}
Var_dump (Getallheaders ());
In fact, this approach is to find the $_server variable with the HTTP_ beginning of the attribute, a string replacement for the property. The http_user_id in the $_server variable is actually the custom User-id above:
$_server Variables in PHP
In addition to the custom HTTP header, you need to pay attention to the naming specification of the header, you cannot use the underscore name, otherwise it is not read under the Nginx server, and when you look up the naming specification, there is a reference to the custom attribute with the X-start problem. Later, I looked up some information and found that the HTTP protocol was not recommended.
The above content is for PHP getallheaders can not get a custom header (headers) related to the issue of the narrative, I hope to help!