phpQuestioner Posted May 24, 2007 Share Posted May 24, 2007 Ok - So I have this code that is supposed to display a random image from an array. I am using PHP Headers to prevent caching; in IE, it works like I want it to, but in FireFox; it keeps caching the first variable in the array. Why is this doing this and how can I make it not cache in any and all browser? <?php // Prevents Browser Cache header("Cache-Control: no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header('Pragma: no-cache'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', FALSE); // This Will Randomly Select An Image To Display $quote = array( 1 => "http://domain.com/pic1.JPG", 2 => "http://domain.com/pic2.JPG", 3 => "http://domain.com/pic3.JPG", ); $randnum = rand(1,3); // this lets php pick an array number 1 through 3 $picselector = $quote[$randnum]; header("Location: $picselector"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52770-having-problem-with-firefox-image-cache/ Share on other sites More sharing options...
448191 Posted May 24, 2007 Share Posted May 24, 2007 I'd say it's because you do a redirect (Location header). When fetching the image the server sends a new set of headers. IE appearantly discards the new headers, FF does what it's supposed to do; respect the new headers. Try something like this: <?php //Headers here $quote = array( 1 => "/img/pic1.JPG", //Replace with FILESYSTEM location of pics 2 => "/img/pic2.JPG", 3 => "/img/pic3.JPG", ); readfile($quote[rand(1, 3)]); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52770-having-problem-with-firefox-image-cache/#findComment-260610 Share on other sites More sharing options...
MadTechie Posted May 24, 2007 Share Posted May 24, 2007 i agree with 448191 but another option is have the link to the image shuffler appended with a random number ie image.php?x=4632432 this would re-download as the file has a "different" name (well not really but don't tell FF that) Quote Link to comment https://forums.phpfreaks.com/topic/52770-having-problem-with-firefox-image-cache/#findComment-260620 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.