Page 1 of 1

Using Image Rotator multiple times doesn't change picture

Posted: Mon Jan 23, 2006 9:34 pm
by Isolder
I can't use any php image rotators to show different random images in my pages. Every time the script is called it always brings back the same picture instead of a different picture. There are plenty image files so it's no coincidence. If anyone has an idea of how to make sure it will give me new randoms each time that would be very helpful.

I am using this as an image rotator:

http://automaticlabs.com/products/rotator

It basically gets a list of files, makes an array count to find out how many they are, and then does rand(0,count($fileList)) to get the image to pull when the script runs.

I've very simply used this like so, 3 times in one html file.

<img src="/rotator.php" />
<img src="/rotator.php" />
<img src="/rotator.php" />


I also tried using it in CSS:

#header {
width:860px;
height:120px;
background: #C6BB9D;
background-image: url("http://www.mysite.com/rotator.php");
background-repeat: repeat-x;
background-position: bottom;
}

The image still never changes. In the CSS I can somewhat guess that it simply only calls that image once and holds the information, but in the HTML it should call the image over and over again for each incarnation.

Posted: Mon Jan 23, 2006 9:45 pm
by josh
have you tried

Code: Select all

print_r($filelist)
:?:

Posted: Mon Jan 23, 2006 9:50 pm
by feyd
given a url, a browser will cache the image returned from it. Thus any further references to that url will result it that image being used.

Generate a "unique" random string of numbers, letters, and symbols to tack onto each call you want to be "different."

Posted: Mon Jan 23, 2006 11:00 pm
by Todd_Z

Code: Select all

$url = "/rotate.php?id=".substr( md5( $time().rand(1,100) ), 0, 8 );

Posted: Mon Jan 23, 2006 11:49 pm
by josh
http://www.php.net/uniqid


md5(uniqid(0)), or instead of defeating the cache you could output the image into the src tag directly from within your script

Code: Select all

<img src="images/rotator/<? echo rand(0,count($filelist) ?>.jpg" />

Posted: Tue Jan 24, 2006 1:07 pm
by Isolder
The unique string on an image call did the trick for me, thanks.

Posted: Tue Jan 24, 2006 3:02 pm
by josh
Todd_Z wrote:

Code: Select all

$url = "/rotate.php?id=".substr( md5( $time().rand(1,100) ), 0, 8 );
Prime example of an error in coding that could result in disaster if register globals was on :D


well, maybe not "disaster"