关于 header() php 的帮助

发布于 2024-09-06 05:06:18 字数 433 浏览 2 评论 0原文

您好,我想在按下后退按钮时从服务器刷新脚本。为此,我使用以下代码:

header( "Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" ); 
header( "Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT" ); 
header( "Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1 
header( "Cache-Control: post-check=0, pre-check=0", FALSE ); 
header( "Pragma: no-cache" ); // HTTP/1.0

但浏览器(IE 8、FF 3.6)似乎仍在“缓存”页面。 任何帮助将不胜感激。

Hello I want to refresh a script from the server when back button is pressed. For that, i'm using this code:

header( "Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" ); 
header( "Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT" ); 
header( "Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1 
header( "Cache-Control: post-check=0, pre-check=0", FALSE ); 
header( "Pragma: no-cache" ); // HTTP/1.0

But it seems the browsers (IE 8, FF 3.6) are still "caching" the page.
Any help will be appreciated.

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

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

发布评论

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

评论(1

玩物 2024-09-13 05:06:18

我确信你实际上无法控制它。后退按钮与新请求完全不同,直到用户代理(在大多数情况下是 MSIE、FF、Chrome、Safari、Opera 等浏览器),并且很可能他们都有自己的解释最终用户在按下后退按钮时需要。在很多情况下,甚至不涉及 HTTP 请求,并且 DOM 会按导航离开之前的状态加载。这包括客户端所做的任何更改。

简而言之:通过您已有的代码来影响和暗示是您能做的最好的事情。要获得“新鲜”页面,用户必须重新加载它(在大多数情况下按 F5)。您可以在页面上添加广告元刷新,以尝试使页面尽可能保持最新状态允许它的用户代理。

I'm convinced you can't actually control it. The backbutton it something entirely diffent from a new request, up to the user-agent (in most contexts a browser like MSIE, FF, Chrome, Safari, Opera and the like), and most likely they all have their own interpretation about what the end user wants when pressing the back button. In a lot of cases, there's not even a HTTP request involved, and the DOM is loaded as it was before navigating away. This includes any alterations done client-sided.

In short: influencing and hinting by the code you already have is about the best you can do. To get a 'fresh' page the user has to reload it (pushing F5 in most instances). You could add ad meta refresh on your page to try to make the page as current as possible in user-agents that allow it.

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