tags:

views:

118

answers:

4

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.

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.

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.

Update

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

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

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?

+6  A: 
<?php header("Cache-Control: no-cache, must-revalidate");
Sarfraz
Ok - this seems to be working in IE, but it is definitely NOT working working in FF. Any ideas why?
croceldon
+1  A: 

Try fooling the browser with a spurious querystring:

header("Location: /webadmin/email/index.php?x=1");
graphicdivine
Cache-Control header is the correct way to do this.
AJ
Yes, this is just a trick, that sometimes can be usefull, but not in this case ;)
DaNieL
'Correct' isn't always practical.
graphicdivine
+6  A: 

I would play safely and try to output all cache killers known to man (and browser). My list currently consists of:

<?php
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " 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
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
danii
Do you happen to know the order of precedence of these different headers? I'm sure it varies per-browser, but would be handy to know for at least IE and FF.
AJ
kill it, burn it, hurl the ashes to the sun in a sealed capsule
Stefano Borini
I just tried all the above, but it still seems to be caching the page.
croceldon
@AJ sorry I don't know the order of preference, it depends really in how closely the browser follows the standards. I do know that "pragma" is for HTTP/1.0 and "cache-control" for HTTP/1.1 (i´ll edit the answer)
danii
+2  A: 

Make all browsers fall in line:

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

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

Derek Illchuk
This seems to work fine - any body have any ideas that would be "pretty"?
croceldon