Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

content expiration

Status
Not open for further replies.

manicleek

Technical User
Jun 16, 2004
143
GB
Is there any PHP code that will make internet explorer (and any other browser) always reload the page rather than use a cached version?
 

Here is the block of headers that I send down to prevent caching (I originally picked them up off a link via Google a while back - sorry for the lack of reference). Check the php manual on headers (and how they have to be the first thing sent to the page etc):

Code:
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache");
header("Cache-Control: post-check=0,pre-check=0");
header("Cache-Control: max-age=0");
header("Pragma: no-cache");

If you use the above block of headers, then you won't get caching on ANY browser (including IE). You can remove some -- but this may cause other browsers to act unexpectedly.

Let us know how you go.

Jeff
 
Maybe you can solve it for IE, but the other browsers behave inconsistently.
Opera for example will not reload the page if the back button is used, even if the above headers are sent. Why?
They interpret the HTTP specification literally, which means a page has only to be reloaded when accessed through a Hyperlink - and using the back button isn't such an instance.
 
I believe IE tends to not bother grabbing a new copy when you press the back button, but this depends on your settings. Most people don't really expect a new copy to be grabbed when you hit back (well... most people I know at least), and it has actually been really annoying a few times when it has happened to me.
 
I actually prefer sometimes, that the "back" button gets a cached version of the site. With 5.5mbit broadband, it's not really an issue, but if someone is on dialup, reloading might be annoying, if useless.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top