faqts : Computers : Programming : Languages : PHP : Common Problems : Caching

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

135 of 152 people (89%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How do I stop PHP pages from being stored in the browser's cache?
What is the Cache-control header used for?

Jun 25th, 2000 22:18
Mark Nottingham, Nathan Wallace, Leon Atkinson,


header("Cache-control: no-cache");
header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");

The first header is for HTTP/1.1 compatible proxies/clients.  The 
second is for HTTP/1.0.  The Cache-control header is the HTTP/1.1
equivilant of the HTTP/1.0 header Pragma: no-cache.

It causes the client (most specifically, proxies) to not cache the
document.  You would use this on something like a realtime banking
session or most any page where the user has been authenticated.

Cache-Control: also adds more features than Pragma. no-store, max-age=?
max-stale=?, min-fresh=?, and only-if-cached.

For more information see the HTTP/1.1 specification at:

    http://www.w3.org/Protocols/Specs.html

also, this may be helpful:

    http://www.mnot.net/cache_docs/