Disable browser caching

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Today I'm using
    <meta http-equiv = "pragma" content = "no-cache">

This prevent the browser to cache the page. So each time I call the  
following PHP script
    echo date("d.m.Y") . " / " . date("H:i:s") . "<br>";
the current time will be displayed.

However, if I call this PHP script over a proxy the time gets not updated.
I always have to press Shift + Reload.

A colleague told me that I have to program the no-caching-command somehow  
within the http header.
How to do that and does this really solve my problem?


Re: Disable browser caching

Stefan Mueller wrote:
Quoted text here. Click to load it

For starters, add cache-control and no-store. See

Using http://php.net/header you can send headers more reliably than
through the meta tag (especially when dealing with proxies).

E. Dronkert

Re: Disable browser caching

On 10/12/2005 20:15, Ewoud Dronkert wrote:


Quoted text here. Click to load it

It should probably be expressed, more strongly than it has been, that  
cache- (Expires, Cache-Control, etc.) and content-related (Content-Type,  
Content-Language, etc.) directives should only be send via HTTP headers.  
Clients will want to know this information /before/ they start parsing  
the entity body, and others won't even look there.

Trying to substitute HTTP headers (any really, but these especially) for  
META elements is very questionable.



Michael Winter
Prefix subject with [News] before replying by e-mail.

Re: Disable browser caching

// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

// HTTP/1.0
header("Pragma: no-cache");

Re: Disable browser caching

I'm using
    Header('Cache-Control: no-cache');
    Header('Pragma: no-cache');

and that works great.

Many thanks

Re: Disable browser caching

*** Stefan Mueller escribió/wrote (Sat, 10 Dec 2005 20:22:50 +0100):
Quoted text here. Click to load it

That's correct. As far as I know, proxies do not parse or even read the
HTML they serve. So HTML is not a good place to give directions :)

-+ Álvaro G. Vicario - Burgos, Spain
++ http://bits.demogracia.com es mi sitio para programadores web
+- http://www.demogracia.com es mi web de humor libre de cloro

Site Timeline