关于 header() php 的帮助
您好,我想在按下后退按钮时从服务器刷新脚本。为此,我使用以下代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确信你实际上无法控制它。后退按钮与新请求完全不同,直到用户代理(在大多数情况下是 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.