Quick Search:
 
 PHP Code: Random banner picker Jump to:  
Category: >> PHP Code >> Random banner picker  

<< lastnext >>

Snippet Name: Random banner picker

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

Also see:
» Random Image from Directory
» Generate random string
» Rounded random numbers
» Random Pronounceable Passwords
» Pick Randomly from Array
» Weighted Random Choice

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

<?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]"  ); 
 
?>


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org