PHPgetallheaders cannot obtain the custom headers. PHPgetallheaders cannot obtain the custom header (headers). phpgetallheaders adds the custom http header when requesting the client. the request is as follows: the custom http request header PHP getallheaders cannot obtain the custom header (headers). phpgetallheaders
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!
Articles you may be interested in:
- Php session_start () about Cannot send session cache limiter-headers already sent error solution
- Sample code for simulating the get_headers function in php
- Use php get_headers to determine whether the URL is valid
- The role and usage of the get_headers function in php
- PHP prompts Cannot modify header information-headers already sent by solution
- PHP error Warning: Cannot modify header information-headers already sent by solution
- PHP uses the get_headers function to determine whether a remote file exists.
- The get_headers function with timeout implemented by PHP
Http://www.bkjia.com/PHPjc/1113707.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1113707.htmlTechArticlePHP getallheaders cannot get the custom header (headers) problem, phpgetallheaders added the custom http header in the client request, the request is as follows: Custom http request header...