/* banner.php
This PHP3 scrolling program was designed by Anton Olsen (aolsen@graphweb.com). You can modify and use this program freely, and spread it freely, If you have made any important changes to it, please write an E-Mail to the editor.
In this program, the author tried to implement this function through many different methods, but the image function in PHP cannot display the animated GIF image format and operate on this format (such as: fopen, fpassthru , and fclose). The author implements it through the passthru method. Although this is not the best method, it can display the advertising banner faster than other methods.
In this program, we assume:
1. You already have a directory that stores all advertising images.
2. All advertising images are in GIF format.
3. All GIF images start with banner.
3. There are no other files in this directory except advertising images.
Install this program:
1. Put this program and all advertising images (*.GIF) into a directory.
2. Place the following HTML code in your WEB page:
@km169.net ) Translate it to Chinese
*/
/* random( $max integer )
Returns a random number from 0 to $max-1;
*/
function random( $max )
{
$x = rand();
$y = getrandmax();
$r = $x / $y * ($max -1 );
$r = round($r++);
return $r;
}
/*Read the directory and put all "banner*" The file is read into an array; */
$i = 0;
$d = dir( ".");
while($entry=$d->read())
if (substr($entry,0,6) == "banner")
$array[$i++] = $entry;
$d->close();
/* Select a random number*/
$r = random( $i );
/* Send a no-cache and gif type file header, and output the image. */
Header( "Pragma: no-cache" );
Header( "Expires: Monday 01-Jan-80 12:00:00 GMT" );
Header( "Content-type: image /gif");
passthru( "cat $array[$r]" );
?>
http://www.bkjia.com/PHPjc/316881.html