Simple script for the rotation of advertising banner.
<?php
/* banner.phtml
Requisites:
Copy all banners in a directory
Banner names must begin with "banner"
no other files in the directory can begin with "banner"
Installation:
Inser the script in the banner folder
Copy all the banners in the same folder
Add the following code to the pages
<a href="www.thelinkedweb.com">
<img src="http://www.yourwebsite.com/directorybanner/banner.phtml" alt="Banner Random" border=0>
</a>
*/
/*
note:
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;
}
/* Look in the directory to get the banner
*/
$i = 0;
$d = dir(".");
while($entry=$d->read())
if (substr($entry,0,6) == "banner")
$array[$i++] = $entry;
$d->close();
/* Gets the banner
*/
$r = random( $i );
/* Send 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]" );
?>
![]()