Her

Home Web Programming PHP Banner rotation and php include

Banner rotation and php include

Author: Kyscorp.com Author's URL: www.kyscorp.com More by this author

Banner Rotation and PHP IncludeBanner 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);

  • 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';

PHP Include

Many scripts use this function to include a page inside another. For instance, you may have a "functions.php" file that contains a list of functions you prepared for your personal use and that you may need for more than just a page.

Instead of pasting the code on each page, just write on every page :

<?
$file="functions.php"; //Here's the file you wish to include.
include($file);
?>

That's just an example but this function is actually widely used.