Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Stop random images from getting displayed twice

$
0
0

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

 

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles