Php method for getting header information for HTTP requests

Source: Internet
Author: User
Php method for getting header information for HTTP requests

<?phpforeach (Getallheaders () as $name = + $value) {echo "$name: $value \ n";}? >

This function can only be used in Apache environment, IIS or Nginx is not supported, can be implemented by custom functions.

<?phpif (!function_exists (' getallheaders ')) {function getallheaders () {foreach ($_server as $name = = $value) {if ( substr ($name, 0, 5) = = ' Http_ ') {$headers [Str_replace (', '-', Ucwords (Strtolower (' _ ', ' ", Str_replace ($name, 5)) )])] = $value;}} return $headers;}}? >

Look at the printed results:

<?phpprint_r (Getallheaders ());

Get results:

Array ([Accept] = */*[accept-language] = zh-cn[accept-encoding] = gzip, deflate[user-agent] = mozilla/ 4.0 (compatible; MSIE 7.0; Windows NT 5.1; trident/4.0;. NET CLR 2.0.50727) [Host] = localhost[connection] = keep-alive)

The above is the content of PHP to get the header information of HTTP request, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

Related articles:

PHP Get header Information implementation steps for HTTP request

PHP HTTP request class, support Get,post,multipart/form-data

PHP implementation of HTTP request Encapsulation example

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