preventing caching

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

preventing caching

Post by 9902468 »

I encountered strange bug that sonmehow prevented me from seeing the changes that I made in my code. After noticing that hitting reload few times solved this problem (Or the *¤##&¤"! words that I shouted...,) I realized that this is most likely browser (or proxy) caching that kindly speeds up my load times...
Anyhow, I can prevent caching with header(), right?, but all solutions I've seen are more or less a bit shaky, and have statement like "This works on netscape x.xx, your mileage may vary." Now, if you could kindly write down what worked for you, or even better, if you know the universal solution to this you are allowed to write it down ;)

thx

-9902468
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

from header-function manual
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
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
looks like a complete round-strike against any chaching ;)
Post Reply