[PHP]Random Image Rotator, But Not Really.

Discussion in 'Web Design & Coding' started by Grandmaster, Aug 22, 2004.

  1. Grandmaster

    Grandmaster Electronica Addict Political User Folding Team

    Messages:
    10,574
    Location:
    Santa Clara, CA
    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? :)
     
  2. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    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 );
    ?>
    
     
    Grandmaster likes this.
  3. Grandmaster

    Grandmaster Electronica Addict Political User Folding Team

    Messages:
    10,574
    Location:
    Santa Clara, CA
    Yeah, after a refresh. Thanks, I forgot about this thread until a couple seconds ago!

    I'll see if this works.
     
  4. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    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 :)