Jump to content

Stop random images from getting displayed twice


Presto-X

Recommended Posts

Hey guys,

 

I'm stumped, I'm trying to pull in a (as in 1) random image from a dir each time the page loads, I have that part down, but what I am having problems with is, if there are only 5 or so images in the folder, you have a 1 in 5 chance that the same image will get displayed twice.  How can I keep this from happening?

 

header("Content-type: image/jpeg");
$img = glob('images/*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$img = $img[array_rand($img)];
imagejpeg(imagecreatefromjpeg($img));

 

 

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.