Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.