Forum Moderators: coopster
I put the script into the directory with the images, it gives ma a random one. We have a pretty good relationship.
Recently, I've been wanting more from my random image scripts. I notice that if I put 2 random images on a page, they both give me the same one.
Is there any way to alter the script so that it returns a new image in each instance of the script that runs on the page?
Here's the one that I'm using right now:
<?
//read folder
$folder=opendir(".");
while ($file = readdir($folder))
$names[count($names)] = $file;
closedir($folder);
//sort file names in array
sort($names);
//remove any non-images from array
$tempvar=0;
for ($i=0;$names[$i];$i++){
$ext=strtolower(substr($names[$i],-4));
if ($ext==".jpg"¦¦$ext==".gif"¦¦$ext=="jpeg"¦¦$ext==".png"){$names1[$tempvar]=$names[$i];$tempvar++;}
}
//random
srand ((double) microtime() * 10000000);
$rand_keys = array_rand ($names1, 2);
//random image from array
$slika=$names1[$rand_keys[0]];
//image dimensions
$dimensions = GetImageSize($slika);
header ("Location: $slika");
?>
I think that part of the problem is that if I have this:
<img src="images/randomscript.php">
appear several times on a page, the browser stores the image, and simply retrieves the same image for every instance.
Is there a way to have it combat this?