我可以使用 php 脚本覆盖/清空 HTTP 响应标头字段,以便不设置该字段吗?

发布于 2024-09-25 13:26:36 字数 77 浏览 1 评论 0原文

如果服务器默认自动发送 Expires HTTP 标头响应,我可以使用 php 脚本覆盖/null 以便不设置 Expires 标头字段吗?

If the server is automatically sending an Expires HTTP header response by default, can I override/null that out with a php script so that the Expires header field is not set?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半夏半凉 2024-10-02 13:26:36

是的,你可以。这将取消发送任何先前设置的 Expires 标头:

header('Expires:');

只有在尚未发送标头的情况下,它才会起作用,因此在您回显某些内容之前,PHP 开始向浏览器发送数据。您可能必须使用输出缓冲来做到这一点。

当您升级到 PHP 5.3.* 时,您还可以使用 header_remove('Expires');

Yes you can. This will cancel any previously set Expires header from being sent:

header('Expires:');

It will only work if no headers have been sent already, so before you echo something and PHP starts sending data to the browser. You might have to use output buffering to do that.

And when you upgrade to PHP 5.3.* you could also use header_remove('Expires');.

走野 2024-10-02 13:26:36

包含默认 Expires 标头的响应取决于您是否使用会话(以及如何使用会话,请参阅 session_cache_limiter

无论如何,如果确实如此,是的,您可以覆盖它,并且您可以使用 header_remove (我没有测试过)。

The response containing a default Expires header depends on whether you're using sessions (and how, see session_cache_limiter)

Anyway, if it does, yes, you can override it and you can probably remove it with header_remove (I haven't tested it).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文