Random Banner Picker

Description: Automatic banner rotation. Randomly selects a banner for display.

<?PHP
 
/*  random(  $max  integer  )
      Returns  a  random  number  between  0  and  $max-1;
*/
FUNCTION  random(  $max  )
{
                $x  =  RAND();
                $y  =  GETRANDMAX();
 
                $r  =  $x  /  $y  *  ($max  -1  );
 
                $r  =  ROUND(  $r++  );
                RETURN  $r;
}
 
/*  Read  the  directory,  add  all  "banner*"  files  with  to  the  array
*/
$i  =  0;
$d      =  DIR( ".");
whle($entry=$d->read())
                IF  (SUBSTR($entry,0,6)  ==  "banner")
                                $array[$i++]  =  $entry;
$d->close();
 
 
/*  pick  a  banner  at  random
*/
$r  =  random(  $i  );
 
/*  Send  a  no-cache  header,  and  the  gif  type  header,  and  output  the  file.
*/
HEADER(  "Pragma:  no-cache"  );
HEADER(  "Expires:  Monday  01-Jan-80  12:00:00  GMT"  );
HEADER(  "Content-type:    image/gif");
PASSTHRU(  "cat  $array[$r]"  );
 
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.