You'll get invited to our Meetups as soon as they're scheduled!
The Seattle PHP Meetup Group Message Board › How do I Stop Cached Images?
| A former member | |
|
|
Ok this is driving me nuts. I have a PHP script for serving images that are dynamically generated via GD. The headers I have are as follows (in order to cache and stop any potential caching that is going on):
header("HTTP/1.1 202 Accepted"); 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, proxy-revalidate, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header ("Cache-Control: max-age=10000000, s-maxage=1000000"); header("Pragma: no-cache"); Unfortunately, IE is still caching the image and reading locally when you change the page. The image created is always the same name. Is there any way to stop IE from caching or is there a workaround? |
| A former member | |
|
|
I ran into this problem and couldn't find a solution.
I did, however, find a workaround. I just added a randomly generated variable to the url of the image generated on the fly. Making the image url different each time the browser loaded it. So if blah.com/images/tada.php is the script that generates the image, I would add a randomly generated urlstring variable to it like this blah.com/images/tada.php?bogus=ax2b3x2 Works like a charm. |
| Caliban Darklock | |
|
|
Is there any way to stop IE from caching or is there a workaround? I always try to structure my image scripts as GET requests so requesting the same URL retrieves the same image. That way, you get all the benefits of caching without the downsides. For example, I have a standard "bargraph.php" script that generates a 1 by 200 pixel graphic based on three parameters: fg and bg for colors, and pct for the percentage complete. If I request: bargraph.php?bg=lightblue&fg=navy& The resulting graphic is a 1 by 200 PNG with 117 pixels of navy on the left and 83 pixels of lightblue on the right. If this result gets cached, it will only get loaded from cache if it's what I wanted anyway, so there's no problem. This isn't always possible, of course. If your image changes over time, you could do a GET request with "date=1135096158" where the date parameter is the current UNIX timestamp. You'd never *benefit* from caching, but web standards would still forbid using a cached result, so if IE continued to cache it would be their bug and not yours. |
| Kyle Mizell | |
|
|
yeah, the easiest way to do it is like the fellow said above...
<img src="images/myimage.jpg?x=<?=tim That will do it, but as the other fellow pointed out, it will never be cached, so you kinda of miss out on that benefit, but I can understand where there are certain circumstances that you would need to do this. |
| simon | |
|
|
i had created a random number generator to stop my form being spammed, but at times if you move from page to page, the image created did not change. so when the send system checked the number to see if it matched the stored confirmation code, it would often show the old image number which would not match the new code.
i added a time and date to the back of the number just like it shows here: <img src="images/myimage.jpg?x=<?=tim you can see it in action here on the uk property buyer site. give me a shout if you would like to share the code. |
| Kerry Usry | |
|
|
I have started using this one from shifting pixel. I am not saying it will fix caching image issues but it is a nice one.
http://shiftingpixel.... I am mainly commenting because I think if you are going to use something like this it is a good idea to hide it and lock out any unauthorized access, I made a suggestion on the resizer below that you could also apply to any one you are using. http://shiftingpixel.... Kerry Edited by Kerry Usry on Sep 1, 2009 11:01 AM |