How to receive http request header information with PHP

little bottle
Release: 2023-04-06 09:28:02
forward
5901 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:
source:cnblogs.com
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!