Vectorials
Flash Perfection
3D Lessons
Tutorialkit
Markup Tutorials
Learn PHP
network
adv banner
Web Programming  Home Web Programming PHP Banner Rotation and PHP Include
rss

Banner Rotation and PHP Include

Author: 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.



Rate this Material: Bad 1 2 3 4 5 Excellent
print this page tell a friend subscribe to newsletter subscribe to rss

Add comments to "Banner Rotation and PHP Include"