【问题标题】:What is removing my headers in PHP/Apache2?什么是在 PHP/Apache2 中删除我的标头?
【发布时间】:2011-03-01 17:06:55
【问题描述】:

我正在使用 PHP 5.3 和 Apache 2.0 来提供一个脚本,该脚本在输出中添加了许多标头:

header('HTTP/1.1 200 OK'); 
header("Content-Type: application/json");
header("Last-Modified: $lastmode"); // $lastmod = Tue, 01 Mar 2011 14:56:22 +0000
header("Etag: $etag"); // Etag = 5da02274fcad09a55f4d74467f66a864

现在,除了Last-ModifiedEtag 之外,所有标题都通过了。在我的 httpd.conf 中,我有以下内容:

Header unset Cache-Control
Header unset Pragma

但在我的回复中,我得到:

HTTP/1.1 200 OK
Date: Tue, 01 Mar 2011 16:49:10 GMT
Server: Apache/2.2.14 (EL) mod_ssl/2.2.14 OpenSSL/0.9.8e-fips-rhel5
Keep-Alive: timeout=15, max=8000
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/json
Expires: 0
Cache-Control: no-cache

我的 Last-ModifiedEtag 标头不见了,我们用 Cache-ControlExpires 代替了它们。

我还应该提到,我已禁用 mod_expires 无济于事。此时我正在拔头发,因为无论我做什么,标题都不存在。什么可能导致它们被删除?

谢谢, J

更新:似乎 Apache 在 PHP 关闭后添加了额外的标头,我认为它也删除了我在上面设置的标头。在PHP中注册一个关闭函数并调用apache_response_headers显示:

Pragma=
Expires=  
Etag=5da02274fcad09a55f4d74467f66a864
Last-Modified=Tue, 01 Mar 2011 14:56:22 +0000
Keep-Alive=timeout=15, max=8000
Connection=Keep-Alive
Transfer-Encoding=chunked
Content-Type=application/json

【问题讨论】:

  • $lastmode$etag 是什么值?
  • 抱歉,我已更新问题以显示值。

标签: php apache http


【解决方案1】:

要回答我自己的问题,我用来调试的工具似乎让我很伤心。首先是 mod_expires 模块导致了问题,但删除它没有效果的原因是我用来调试问题的代理(Charles)似乎修改了标题。一旦查尔斯被带出循环,我的标题就在那里!

【讨论】:

    猜你喜欢
    • 2011-05-26
    • 1970-01-01
    • 2020-08-25
    • 2010-12-28
    • 2012-01-23
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    相关资源
    最近更新 更多