html calling for a random image:
<img src="/test/art/rotate.php?i=0">
<img src="/test/art/rotate.php?i=1">
<img src="/test/art/rotate.php?i=2">
php file i'm accessing:
<?php
// rotate images randomly but w/o dups on same page - format:
// <img src='rotate.php?i=0'> - rotate image #0 - use 'i=1'
// for second, etc
// (c) 2004 David Pankhurst - use freely, but please leave in my credit
$images = array_unique($images);
$images=array( // list of files to rotate - add as needed
"img5.jpg",
"img6.jpg",
"img7.jpg",
"img8.jpg",
"img9.jpg",
"img10.jpg",
"img11.jpg",
"img12.jpg",
"img13.jpg",
"img14.jpg",
"img15.jpg",
"img16.jpg", );
$total=count($images);
$secondsFixed=3600; // seconds to keep list the same
$seedValue=(int)(time()/$secondsFixed);
srand($seedValue);
for ($i=0;$i<$total;++$i) // shuffle list 'randomly'
{
$r=rand(0,$total-1);
$temp =$images[$i];
$images[$i]=$images[$r];
$images[$r]=$temp;
}
$index=(int)($_GET['i']); // image index passed in
$i=$index%$total; // make sure index always in bounds
$file=$images[$i];
header("Location: $file"); // and pass file reference back
?>
I get images to display, but there are duplicates. I think this is because every call to the php file is a new call, the already loaded images aren't remembered as already loaded. How do I prevent showing duplicates?
Aucun commentaire:
Enregistrer un commentaire