PHP : Show the headers received from the browser

标签 php

因此,当浏览器向服务器发出 HTTP 请求时,它采用一些 header (get/post、cookies、host、User Agent 等)的形式。有没有一种方法可以在 php 脚本中读取和显示它们?是的,$_GET、$_POST 和 $_COOKIE 都在那里。我正在寻找其余的标题信息。例如http://pgl.yoyo.org/http/browser-headers.php谢谢。

最佳答案

get_headers()功能是你要找的。如引用

get_headers — Fetches all the headers sent by the server in response to a HTTP request

简单的例子:

$url = 'http://www.example.com';   
print_r(get_headers($url));   

输出服务器发送的所有信息:

Array (

[0] => HTTP/1.1 200 OK
[1] => Date: Sat, 29 May 2004 12:28:13 GMT
[2] => Server: Apache/1.3.27 (Unix)  (Red-Hat/Linux)
[3] => Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
[4] => ETag: "3f80f-1b6-3e1cb03b"
[5] => Accept-Ranges: bytes
[6] => Content-Length: 438
[7] => Connection: close
[8] => Content-Type: text/html )

更新

要接收浏览器发送的信息,可以从 $_SERVER 访问它们。 super 全局变量。例如,以下代码片段给出了所有浏览器相关信息。

echo $_SERVER['HTTP_USER_AGENT'];

同样,

  • REQUEST_METHOD : 给出 HTTP 请求方法,如 GET、HEAD、Put、Post
  • HTTP_HOST: 给出HOST信息
  • HTTP_COOKIE:给出关于 Cookie header 的原始信息 [Source]

关于PHP : Show the headers received from the browser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12024479/

相关文章:

php - 在 PHP MYSQL 中 POST FORM 的更短方法

php - 用户日期范围输入与 MySQL 中的一系列日期范围相比较

php - Codeigniter 多个 foreach 循环

PHP 在一个查询中检查另一个值

php/mysql SERF 网址

php - 在php中的std对象中添加方法

php - 我如何获取关键字中的文本?

php - 使用 Laravel - Php 将输入值传递给 URL

php - 单击一个数据后如何查看数据库中的所有字段

php - 如何解决 Laravel - 无法找到驱动程序错误?