>> KYSCORP.COM TUTORIALS >> PHP Tutorials
Banner Rotation
With this script you can add a banner rotation to your site, the base code is:
$file = 'data.txt';
$images[0] = 'banner1.gif';
$images[1] = 'banner2.gif';
$images[2] = 'banner3.gif';
$images[3] = 'banner4.gif';
$fp = fopen($file, 'r');
$data = fread($fp, filesize($file));
fclose($fp);
if($data >= count($images)) $data = 0;
echo $images[$data];
$data++;
$fp = fopen($file, 'w');
fwrite($fp, $data);
fclose($fp);
$images[0] = 'banner1.gif';
$images[1] = 'banner2.gif';
$images[2] = 'banner3.gif';
$images[3] = 'banner4.gif';
$fp = fopen($file, 'r');
$data = fread($fp, filesize($file));
fclose($fp);
if($data >= count($images)) $data = 0;
echo $images[$data];
$data++;
$fp = fopen($file, 'w');
fwrite($fp, $data);
fclose($fp);
- Create data.txt file, set its content to 0 (Zero) CHMOD it to 777
- Change banner1.gif, banner2.gif .... to the name of your banners (including
the paths to them if needed)
- You may add as much banners as you need, just add a new line to the code, for
instance to add a 5th banner called banner5.gif to this code just add this line:
$images[4] = 'banner5.gif';
- That's all, Enjoy !!