PHPWhile caching makes every Internet user’s life so much better, there are of course times when it can be an absolute bane as well – especially when you are manipulating database record sets and generating graphs off them!

And seeing as this is exactly what is happening with all my nifty flash-based graphs for the compliance reporting system that I am currently working on, I thought I’d quickly store a note regarding how to disable caching on a specific PHP script page.

The trick is of course to make use of HTML header information and thus at the top of your page (and I mean right at the top), simply enter the following code to achieve our nifty little cache blocker:

header(‘Cache-Control: no-cache, no-store, max-age=0, must-revalidate’);
header(‘Expires: Mon, 12 Jul 1996 04:11:00 GMT’); //Any date passed.
header(‘Pragma: no-cache’);

(Note, if you don’t like the idea of modifying your headers you could always do something like include uniquely generated GET variables that need to be passed to every page, because obviously the ever changing URL would then appear to be a new URL not yet viewed.)