简体   繁体   English

如何在php中获取当前页面的所有HTTP响应头

[英]How to get all the HTTP response headers of the current page in php

headers_list() and apache_reponse_headers() return a greatly reduced list of the actual response headers, even after headers_sent() and get_headers() would make another HTTP request. headers_list()apache_reponse_headers()返回一个大大减少的实际响应头列表,即使在headers_sent()get_headers()发出另一个HTTP请求之后也是如此。

So, how can you get the complete list of response headers that are to be sent with the current page, or are these additional response headers, as set by the server, only set long after PHP has finished? 那么,如何获得与当前页面一起发送的响应头的完整列表,或者这些额外的响应头(由服务器设置)仅在PHP完成后设置很久?

The hosting webserver is free to add headers. 托管网络服务器可以免费添加标题。 For example, it may transparently compress php's output, set Strict-Transport-Security headers, and so on. 例如,它可以透明地压缩php的输出,设置Strict-Transport-Security标头等等。 In some setups (for example wikimedia's ), the request is also proxied by another HTTP server on another machine to allow caching. 在某些设置(例如维基媒体 )中,请求也由另一台机器上的另一个HTTP服务器代理以允许缓存。

Therefore, there is no way to get the complete list of sent HTTP headers. 因此,无法获取已发送HTTP标头的完整列表。 Why would you want to have that anyway? 你为什么要这样呢?

Thing is most of the headers are sent by the server, not the PHP script itself. 事情是大多数标题是由服务器发送的,而不是PHP脚本本身。 Sure, you can send headers inside a script, but that won't mean you'll get all the ones sent after the page has been loaded. 当然,您可以在脚本中发送标题,但这并不意味着您将在页面加载后获得所有已发送的标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM