PHP Getallheaders Unable to get custom header headers problem

Source: Internet
Author: User
Tags nginx server
A custom HTTP header was added at the time of the client request, as follows:

Custom HTTP request Headers

Var_dump (getallheaders);

It started with the getallheaders parameter, but found that it was not available on Nginx deployed servers, 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 = = $va Lue) {if (substr ($name, 0, 5) = = ' Http_ ') {$headers [Str_replace (', '-', Ucwords (Strtolower (' _ ', ' "," Str_replace ( $name, 5)))])] = $value;}} return $headers;}} Var_dump (Getallheaders ());

In fact, this method is to find the $_server variable in the beginning of the Http_ property, the property to do a string substitution. 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, cannot be named under the underscore, otherwise under the Nginx server can not read, when looking for the naming specification, there is a reference to the custom attribute X-Start the problem. Later, I looked up some information and found that the subsequent HTTP protocol was not recommended.

The above content is for PHP getallheaders unable to get the custom header (headers) of the relevant narrative, I hope to help you!

The above describes the PHP getallheaders can not get the custom header headers problem, including the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.