Re: Internet Explorer Caching

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I forgot to mention in my question that only IE appears to cache. And with the way my PHP program goes, I'm constantly changing the URL as I go through the application to modify data and status message. But whenever I return the the edit page, the old data is showing up.

Charlene

Richard Lynch wrote:
On Wed, August 29, 2007 10:43 am, Charlene wrote:
I've been having problems with Internet Explorer caching php programs.
I'm using the following code:

        header("Cache-Control: no-cache, must-revalidate"); //
HTTP/1.1
        header("Pragma", "no-cache");
        header("Expires", "-1");

And it used to work, but now, according to Windows Explorer its giving
it 3 hours to expire.

The second argument to header() function will allow you to send
"duplicate" headers for the same header-name.

header("Pragma: no-cache");
header("Pragma: must-revalidate");

This is usually NOT what you want for headers, as MOST of them allow
only ONE instance.

So header("Pragma", "no-cache");
is sending a SECOND "Pragma" header.

Actually, as you have no ":" in there, it probably is sending it with
no ":", so it's really the first completely bogus "Pragma" header
which is doing absolutely nothing, and isn't a "Pragma:" header at
all.

I guess technically it's maybe not bogus...  You're allowed to extend
the HTTP protocol and send "extra" headers, but they're supposed to
start by "X-" by convention...

//legit
header("X-my-custom-header: 42");

//certainly not convention; probably not legit
header("My-custom-header: 42");

But it's sure not the "Pragma: no-cache" header you MEANT to send.

Ditto for Expires.

And double-ditto for the -1 value for "Expires", which I do not think
is a valid value.

Now IE may have decided to stop doing an interpretive dance around the
bogus headers you have been sending, and has decided it's time to make
you send the REAL headers.  Personally, I think it should never have
let you get away with it in the first place, but that's IE for ya.

ULTIMATELY, however, if you really really really want MS IE nor any
intermediary servers to cache something, your best bet is to add some
random bit to the URL:

<?php $ms_sucks = md5(uniqid(mt_rand(), 1));?>
<a href="whatever.php?ms_sucks=<?php echo $ms_sucks?>">can't cache
this</a>

There is no combination of headers for no-cache that will actually
WORK for *ALL* legacy browsers.

Please Note: When I say *ALL* legacy browsers, I'm including
everything back to NCSA Mosiac and corporate re-branded IE with their
own nifty logo in place of the IE logo.

AT&T, for example, does/did this for their employees -- and the
version number may match exactly with the publicly-available IE, but
they don't behave the same, in my experience. :-(

Given that it's a heck of a lot easier to generate a random URL than
fiddle with so-called "no-cache" headers every time a bug report from
some browser you never even heard of rolls in, I strongly recommend
using a random URL.

YMMV


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux