Using Image Rotator multiple times doesn't change picture

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Isolder
Forum Newbie
Posts: 2
Joined: Mon Jan 23, 2006 9:17 pm

Using Image Rotator multiple times doesn't change picture

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

have you tried

Code: Select all

print_r($filelist)
:?:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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."
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Code: Select all

$url = "/rotate.php?id=".substr( md5( $time().rand(1,100) ), 0, 8 );
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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" />
Isolder
Forum Newbie
Posts: 2
Joined: Mon Jan 23, 2006 9:17 pm

Post by Isolder »

The unique string on an image call did the trick for me, thanks.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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"
Post Reply