Jump to content

Having Problem with FireFox Image Cache


phpQuestioner

Recommended Posts

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");

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/52770-having-problem-with-firefox-image-cache/
Share on other sites

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)]);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.