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