Semplice script per la rotazione di banner pubblicitari.
<?php
/* banner.phtml
Requisiti:
Copiare i banner in una directory
I nomi dei file iniziano con "banner"
non ci sono altri file nella directory che iniziano con "banner"
Installazione:
Mettere lo script nella directory dei banner
Mettere tutti i banner nella stessa directory
Aggiungere il seguente codice alle pagine
<a href="www.sitolinkato.com">
<img src="http://www.iltuosito.com/directorybanner/banner.phtml" alt="Banner Random" border=0>
</a>
*/
/*
nota:
random( $max integer )
restituisce un numero casuale tra 0 e $max-1;
*/
function random( $max )
{
$x = rand();
$y = getrandmax();
$r = $x / $y * ($max -1 );
$r = round( $r++ );
return $r;
}
/* Legger la directory per trovare i banner
*/
$i = 0;
$d = dir(".");
while($entry=$d->read())
if (substr($entry,0,6) == "banner")
$array[$i++] = $entry;
$d->close();
/* Prende un banner
*/
$r = random( $i );
/* Invia il file
*/
Header( "Pragma: no-cache" );
Header( "Expires: Monday 01-Jan-80 12:00:00 GMT" );
Header( "Content-type: image/gif");
passthru( "cat $array[$r]" );
?>
![]()
![]()