figo2476 Posted May 22, 2008 Share Posted May 22, 2008 Basically, a image will be updated over time, but it is always has the same name. Safari and firefox understand the difference and will load the latest image. IE6,7 have a little problem and it will load the cache image. I have tried <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 ?> <?php header('Pragma: no-cache'); ?> It doesn't work in all browsers and I guess the php page flow is not as simple as from top to bottom. It won't be desirable, since the page has many images and it should reload a particular image. Not sure how to work around this.... Quote Link to comment Share on other sites More sharing options...
phpzone Posted May 22, 2008 Share Posted May 22, 2008 I'm not sure of the real cause, but have you also set an expiry date on the entire page with meta expires? Quote Link to comment Share on other sites More sharing options...
thebadbad Posted May 22, 2008 Share Posted May 22, 2008 If nothing else works, you could put a random query string on the image path, like: <?php echo '<img src="some_image.jpg?', uniqid(), '" alt="" />'; ?> Will output something like <img src="some_image.jpg?48353bab35680" alt="" /> And the same image "some_image.jpg" will always be loaded, but it will look different to the browser every time (the query string does nothing to the image). Quote Link to comment Share on other sites More sharing options...
kev wood Posted May 22, 2008 Share Posted May 22, 2008 to ad the expiry date header you should always use a date which is set in the past the line you should use should look like this header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); when ever i have had problems with images being cached i have added the random number to them i find it works better than trying to stop the caching of the images. the random number syntax i use it this $rand = rand (0,100); <img src = "your_image.gif.'?'.$rand" that line of code should display the image with a number appended to the end of the file so it will always have some part of the file which is different to the last it tried to display Quote Link to comment Share on other sites More sharing options...
thebadbad Posted May 22, 2008 Share Posted May 22, 2008 so it will always have some part of the file which is different to the last it tried to display Well, not always with rand(0, 100), that's why I used uniqid(). Quote Link to comment Share on other sites More sharing options...
kev wood Posted May 22, 2008 Share Posted May 22, 2008 point taken but it still only has a 1 in 100 chance of displaying the same file, and the number could just be given a bigger range to work from. Quote Link to comment Share on other sites More sharing options...
mlin Posted May 22, 2008 Share Posted May 22, 2008 thebadbad's solution will be faster and better chance of getting the results you want...go with that. Never seen that before...very clever thebadbad Quote Link to comment Share on other sites More sharing options...
figo2476 Posted May 23, 2008 Author Share Posted May 23, 2008 Wow.. thank you for everyone. Hmm.. Not sure why IE6, 7 cannot figure it out. FF and safari understand the difference of same name, but modified file. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.