PHPgetallheaders cannot get the custom header (headers). phpgetallheaders_PHP tutorial

Source: Internet
Author: User
Tags php error
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...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.