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

How to receive http request header information with PHP

little bottle
Release: 2023-04-06 09:28:02
forward
6081 people have browsed it

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";
}
Copy after login

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;
}
Copy after login

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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template