PHP删除HTTP标头 [英] PHP remove HTTP header

查看:97
本文介绍了PHP删除HTTP标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为Apache会将这些HTTP标头添加到PHP脚本生成的所有响应中:

Something, I think Apache, adds these HTTP headers to all responses generated by PHP scripts:

Expires:   Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control:  no-store, no-cache, must-revalidate, post-check=0, pre-check=0

这适用于实际的动态页面,但我有一些页面,虽然由PHP生成,但大多数是静态的,我希望浏览器缓存它们。

This works ok for actual dynamic pages, but I have some page that, while generated by PHP, are mostly static, and I want the browser to cache them.

是在PHP中有一种方法可以从响应中删除这些标题,从而激活浏览器的默认缓存规则,或者如果没有,是否有任何值可以将它们设置为等同于它们不存在?

Is there a way in PHP to remove those headers from the response, and thus activate the browser's default caching rules, or if not, is there any value I can set them to that's equivalent with them being absent?

我不想设置自己的值,因为我希望浏览器使用与Apache本身提供的静态资源相同的缓存规则(不使用mod_cache)。

I would prefer not to set my own values, because I want the browser to use the same caching rules as for static resources that are served by Apache itself (without using mod_cache).

推荐答案

首先,我要检查它是否真的不是设置这些标题的php脚本之一。

First I'd check if it really isn't one of the php scripts that sets these headers.

register_shutdown_function('foo');
echo "test";

function foo() {
  flush();
  $c = "headers_list: \n  " . join("\n  ", headers_list());

  if ( function_exists('apache_response_headers') ) {
    $c .= "\napache_response_headers:";
    foreach( apache_response_headers() as $k=>$v) {
      $c.= "\n  $k=$v";
    }
  }
  $c .= "\n\n";
  echo '<pre>', $c, '</pre>';
}

这会在您的服务器上打印可用吗?

Does this print something "usable" on your server?

这篇关于PHP删除HTTP标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆