我有网页A。用户点击表单来提交数据,然后把他带到网页B。当他点击后退按钮时,我需要从服务器刷新网页A,而不是从缓存加载。我有一个:<meta http-equiv="expires" content="0">,但它似乎不起作用。我还尝试在页面B(会话变量通过php)上设置一个变量,然后在页面A上检查它,并根据它的存在刷新(或不刷新)。这件事似乎也很管用。它的基本代码是:A页:
<?php
if(isset($_SESSION['reloadPage'])) {
unset($_SESSION['reloadPage']);
echo'
<script>
window.location.replace("/****/****/*****.php");
</script>
';
}
?>在B页:
$_SESSION['reloadPage'] = 1;对于PHP解决方案,它只是不断地尝试在一个永无止境的循环中刷新页面。我的逻辑中缺少了什么?这样做对吗?
在进一步研究之后,编辑,当您告诉浏览器不要缓存页面时,这是否也会强制服务器端进行全面刷新?这正是我所需要的。页面的完整服务器端刷新。
发布于 2012-04-12 21:59:40
好的,试一试:
<?php
if(!session_id()) {
@session_start();
}
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
if(isset($_SESSION['form_submitted'])) {
unset($_SESSION['form_submitted']);
header('Location: ?' . uniqid());
#header('Refresh: 0');
}
?>您需要在第2页中设置$_SESSION‘’form_submitted‘= true。
发布于 2012-04-12 21:58:15
试着用这三种方法:
<meta http-equiv="cache-control" content="no-cache"> <!-- tells browser not to cache -->
<meta http-equiv="expires" content="0"> <!-- says that the cache expires 'now' -->
<meta http-equiv="pragma" content="no-cache"> <!-- says not to use cached stuff, if there is any -->发布于 2012-04-12 22:08:54
<?php
session_start();
if(isset($_SESSION['reloadPage'])) {
unset($_SESSION['reloadPage']);
//no outputting code above header
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header("Location: http://www.mypage.com/");
}
?>https://stackoverflow.com/questions/10132446
复制相似问题