• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

[PHP]Random Image Rotator, But Not Really.

Grandmaster

Electronica Addict
Political User
#1
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? :)
 

Khayman

I'm sorry Hal...
Political User
#2
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 );
?>
 

Khayman

I'm sorry Hal...
Political User
#4
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 posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,016
Latest member
poordown814