Home>Article>Backend Development> How to receive http request header information with PHP

How to receive http request header information with PHP

little bottle
little bottle forward
2019-04-23 13:58:15 5910browse

This article mainly talks about using PHP to receive HTTP request header information. It has certain reference value. Interested friends can learn about it.

1. PHP comes with the function getallheaders()

  • Currently getallheaders() can only be used in apache. If you want to use it in nginx, you can use a custom function.


foreach (getallheaders() as $name => $value) { echo "$name: $value\n"; }

2. Custom function


function em_getallheaders() { $headers = []; foreach ($_SERVER as $name => $value) { if (substr($name, 0, 5) == 'HTTP_') { $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; } } return $headers; }

Related tutorials:PHP video tutorial

The above is the detailed content of How to receive http request header information with PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete