<?php
$banners = array();
// aggiungi qui le immagini
$banners[] = array(
    'src'  => 'http://www.example1.com/banner1.png',
    'href' => 'http://www.example1.com',
);
$banners[] = array(
    'src'  => 'http://www.example2.com/banner2.png',
    'href' => 'http://www.example2.com',
);
$banners[] = array(
    'src'  => 'http://www.example3.com/banner3.png',
    'href' => 'http://www.example3.com',
);
// tempo di rotazione (in secondi)
define('ROTATION_TIME', 15);
define('FNAME', substr(sha2('last_banner'), 0, 10) . '.txt');
$newBanner = false;
// se il file contenente i dati non esiste visualizza il primo banner
if (!is_file(FNAME)) {
    $bannerId = 0;
    $newBanner = true;
} else {
    // recupera le informazioni dal file
    $contents = file_get_contents(FNAME);
    $data     = unserialize($contents);
    // se dall'ultima visualizzazione è passato il tempo di rotazione...
    if (time() - $data['time'] > ROTATION_TIME) {
        // se l'ultimo banner visualizzato è l'ultimo disponibile, ricomincia
        // da capo, altrimenti passa al successivo
        if ($data['banner_id'] == count($banners) - 1) {
            $bannerId = 0;
        } else {
            $bannerId = $data['banner_id'] + 1;
        }
        $newBanner = true;
    } else {
        // se il tempo di rotazione non è passato visualizza ancora l'ultimo
        // banner
        $bannerId = $data['banner_id'];
    }
}
// se bisogna aggiornare i dati
if ($newBanner) {
    // crea il nuovo array
    $newData = array(
        'banner_id' => $bannerId,
        'time'      => time(),
    );
    // scrivi l'array serializzato nel file
    file_put_contents(FNAME, serialize($newData));
}
$banner = $banners[$bannerId];
// visualizza il codice HTML per il banner
echo <<<EOF
<a href="{$banner['href']}">
    <img src="{$banner['src']}" />
</a>
EOF;
?>