View Full Version : Page caching challenge

01-17-2012, 04:33 PM
Hi All,

The following code i was told does not cache, it works fine sometimes and sometimes does not (caches). I do not want the page to cache.

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");

What might be the possible cause and fix to it? Your help is much appreciated.


01-17-2012, 05:45 PM
Is there a particular thing on a page that should not cache, or the entire page?
I'm sort of thinking that maybe PHP SESSION might be something you could utilize.

01-17-2012, 06:41 PM
There's nothing you can do to stop a browser caching a page - if the browser wants to cache a page, it will, and it's beyond your control, because you have no idea who is going to use what on the client-side to view your web page.

You should aim to write code that works whether or not the page is cached.

01-17-2012, 07:20 PM
XmisterIS ... you are correct, but what a PHP outputs to the browser "on the fly"
can be controlled. Sure, someone can take a snapshot of a page at any given time,
but when they or anyone else returns to it, the page will be changed no matter how
much caching they do. The web page they are viewing is not "static". It's rendered
on the fly.