Re: Browser Caching

From: Date: Sun, 29 Apr 2001 18:33:01 +0000
Subject: Re: Browser Caching
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-50820@lists.php.net to get a copy of this message
On 29 Apr 2001 07:19:15 -0700, Steve Haemelinck <steve@haemelinck.be> wrote: > I thought this was because the page might be cached, but when I set the > header("cache-control: no-cache") & the meta tag http-equiv="Expires" > content="-1" it still produces the same effect. How can I solve this > problem? Have you tried with the other HTTP headers for expiration? This is floating around various places - the PHP manual, etc. 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-cache, must-revalidate"); // HTTP/1.1 header("Pragma: no-cache"); // HTTP/1.0 If that doesn't work (IE/NS can be really buggy with caching - I once had a problem where a page started returning a 500 error code and IE5 continued to display the old version of that page, even though I had set the cache to check every time), some alternatives come to mind: - Embed some random variable in the URL. I think this is the cleanest way of dealing with browsers which ignore the HTTP headers - simply start encoding the session ID in your links or even something like "&DontCacheThisPage=" . time(). If the URLs are different, the browser won't cache them, which should sidestep the issue. If for some reason you can't do that and don't mind kludgy looking code: - Use POST. It's ugly and nasty but the browsers are better about always reloading pages which are the response to a POST request. - Equally ugly, use JavaScript. When you change a document's location, there's a parameter which if true will cause the browser to reload the page even if it's cached. The least ugly way of doing this would be to write a function and put it in a handler ('OnClick="return forceLoad('myurl');"') so that poeople w/o JS will still be able to use your pages.

« previous php.general (#50820) next »