[PHP]Random Image Rotator, But Not Really.

Grandmaster

Electronica Addict
Political Access
Joined
3 Feb 2002
Messages
10,574
Let me explain. I've used random image rotators, but they aren't really what I want. Because all the random image rotators I've used, are well, too random :p Sometime they display the same image two or three times. I don't like that.

I want the ability to display a set of images in an order I want. I'm sure it is possible...so can any of you PHP gurus help me out here? :)
 
when do you want the image displayed? after a refresh?
Well thats what this bit of code does, probably overly complicated but it was of the top of my head. There are many other ways of doing it (could scan a directotry and pick the files in order, or use mysql etc)
Code:
<?
$picture_order = array("bg02.gif", "bg03.gif", "bg06.gif", "bg07.gif");

$picture_compare = $_COOKIE["pic"];
	if(!isset($picture_compare))
		$picture_compare=$picture_order[0];
		
$found =false;
$counter = 0;
foreach ($picture_order as $value)
{		

	if ($found) break;
	if (!strcasecmp($picture_compare, $value))
		$found=true;		
	else
		$found =false;
	$counter++;
}

if($counter==count($picture_order)) $value= $picture_order[0];

$file=$value;

setcookie("pic", "$file", time()+3600, "/");
if ( eregi( '.jpg$', $file ) ) {
header( "Content-Type: image/jpeg" );
} else {
header( "Content-Type: image/gif" );
}
header( "Content-Length: " . filesize( $file ) );
readfile( $file );
?>
 
Yeah, after a refresh. Thanks, I forgot about this thread until a couple seconds ago!

I'll see if this works.
 
Well it should work, cause i tried it obviously :)

Whether it works the way you want is another matter :)

Subscribe to topic is your friend :)
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back