Sign in to follow this  
benryves

[web] [PHP/HTTP] Forcing Firefox to redownload an image

Recommended Posts

Firefox, as usual, decides to hold on to some graphs for dear life and never redownload them (I've had problems in the past with it holding on to CSS files, meaning that angry people complain that I haven't updated the styles they requested). *sighs* Anyway, I thought this would be the fix: # Set up the correct header: header("Content-type: image/{$format}"); header("Pragma: no-cache"); header("Cache-Control: no-store, no-cache, must-revalidate"); This (unsurprisingly) works fine in IE. Firefox will not redownload the images, however. Is there any way to force it to do so?

Share this post


Link to post
Share on other sites
I believe that your code causes Firefox only to not cache the HTML page, not the images/files which it is linked to. It is probably possible to set up your web server (assuming Apache) to output the header you just described so that all images/CSS files aren't cached.

Cheers!

Share this post


Link to post
Share on other sites
I seem to remember that you need to do something like:

<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="expires" content="0">

or

<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="expires" content="Mon, 01 Jan 1990 00:00:01 GMT">

to get it to work in both IE and Mozilla/Firefox. However, I could be wrong as I don't have access to the page I did this with at the moment.



Share this post


Link to post
Share on other sites
Bah, sorry. I should have said - these headers are being sent by the image itself, (and hence the header("Content-type: image/{$format}");), and not by the page it is on. Meta tags wouldn't be of much use, in this case.

Share this post


Link to post
Share on other sites
I can't remember... is there a Last-Modified header, or similar?

Edit: Apparently, there is. I can't tell you whether using it will make Firefox redownload the image, but you could try it.

John B

Share this post


Link to post
Share on other sites
I use this:


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-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");


Never failed me so far!

Share this post


Link to post
Share on other sites
Sander: I've seen that exact listing of headers before, but Firefox still ignores it. I've come up with an even easier solution - what this is is an image of a graph on a page that has the URL rewritten by some JavaScript as you select options in dropdown boxes and option buttons. I just stick &current_timestamp on the end of the URL which "stops" the image from staying in the cache as it is no longer seen as being the same image.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this