强制页面从服务器重新加载而不是加载缓存版本 [英] Force page to reload from server instead of load the cached version

查看:165
本文介绍了强制页面从服务器重新加载而不是加载缓存版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有网页A.用户点击表单提交数据,然后将他带到网页B.当他点击后退按钮时,我需要从服务器刷新网页A,而不是从缓存加载。我有这个:< meta http-equiv =expirescontent =0> 但它似乎无法正常工作。我也尝试在页面B上设置变量(通过php设置会话变量)然后在页面A上检查它并根据它的存在刷新(或不刷新)。这种做法似乎也有效。基本代码是:
页面A:

I have webpage A. The user clicks on a form to submit data, and it takes him to webpage B. When he clicks the back button, I need webpage A to be refreshed from the server, rather that loaded from cache. I have this: <meta http-equiv="expires" content="0"> but it doesnt seem to work. I have also tried setting a variable on page B (session variable via php) and then check for it on page A and refresh (or not) according to its existence. This doest seem to work either. The basic code for that is: Page A:

<?php 
if(isset($_SESSION['reloadPage'])) {
unset($_SESSION['reloadPage']);
echo'
<script>
window.location.replace("/****/****/*****.php");
</script>
';
}
?>

在页面B上:

$_SESSION['reloadPage'] = 1;

使用PHP解决方案,它只是不断尝试在永无止境的循环中刷新页面。我的逻辑缺少什么?这是正确的方法吗?

With the PHP solution, it simply keeps trying to refresh the page in a never ending loop. Something in my logic missing? Is this the right way to go about it?

编辑
进一步调查后,当您告诉浏览器不缓存时页面,是否强制完整的服务器端刷新?这就是我需要的。页面的完整服务器端刷新。

EDIT Upon further investigation, when you tell the browser to not cache the page, does that force a full server side refresh as well? That's what I need. A full server side refresh of the page.

推荐答案

确定试试这个:

<?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。

You will need to set $_SESSION['form_submitted'] = true on page 2.

这篇关于强制页面从服务器重新加载而不是加载缓存版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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