php中如何获取当前页面的所有HTTP响应头
即使在 headers_sent()
和 get_headers( )
将发出另一个 HTTP 请求。
那么,如何获取要与当前页面一起发送的响应标头的完整列表,或者这些额外的响应标头(由服务器设置)仅在 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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
托管网络服务器可以免费添加标头。例如,它可以透明地压缩 php 的输出,设置 Strict-Transport-Security 标头,等等。在某些设置中(例如 wikimedia 的),请求也会被代理 em> 由另一台机器上的另一个 HTTP 服务器允许缓存。
因此,无法获取发送的 HTTP 标头的完整列表。 为什么你还是想拥有它?
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. In some setups (for example wikimedia's), the request is also proxied by another HTTP server on another machine to allow caching.
Therefore, there is no way to get the complete list of sent HTTP headers. Why would you want to have that anyway?
问题是大多数标头都是由服务器发送的,而不是 PHP 脚本本身。当然,您可以在脚本内发送标头,但这并不意味着您会在页面加载后收到所有发送的标头。
Thing is most of the headers are sent by the server, not the PHP script itself. 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.