如何强制页面不在PHP中缓存? [英] How to force page not to be cached in PHP?

查看:135
本文介绍了如何强制页面不在PHP中缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面index.php,它显示基于mysql db的信息.上面有表单,表单的操作设置在一个单独的页面上,称为process.php. Process.php完成所有数据库CRUD的工作,然后使用

I have a page, index.php, that shows information based on a mysql db. There are forms on it, and the action for the forms is set to a separate page called process.php. Process.php does all the database CRUD stuff, then uses

header("Location: /webadmin/email/index.php");

将用户发送回原始页面.

to send the user back to the original page.

除了原始索引页面并不总是反映process.php所做的更改之外,这似乎还不错.我认为该页面已被缓存,因为如果刷新(Ctrl + F5),页面将显示最新数据.

This seems to be working fine, except for the fact that the original index page doesn't always reflect the changes made by process.php. I assume that the page is being cached, because if I do a refresh (Ctrl + F5), the page will show the latest data.

如何防止此页面被缓存?我已经尝试 header()的PHP页面说了什么,但是它没有似乎行得通. Cache-Control和Expires选项似乎完全无效-该页面仍在缓存中.

How can I prevent this page from being cached? I have tried what the PHP page for header() says, but it doesn't seem to work. The Cache-Control and Expires options seem to have no effect at all - the page is still being cached.

更新

好吧,我在某种程度上错了.显然,以下内容在IE中确实有效:

Ok, I was partially wrong. Apparently, the following does work in IE:

<?php header("Cache-Control: no-cache, must-revalidate");

但是,它绝对不能在FF中使用,后者仍显示缓存的版本.关于这是为什么的任何想法,以及如何使它停止缓存?

However, it is definitely NOT working in FF, which is still showing a cached version. Any ideas on why this is, and how I can make it stop caching?

推荐答案

使所有浏览器排在一行:

header("Location: /webadmin/email/index.php?r=".mt_rand(0, 9999999));

虽然不漂亮,但适合提出的问题:如何 强制 ..."

It's not pretty, but it fits the question asked: "How to force..."

这篇关于如何强制页面不在PHP中缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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