PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Banner Rotation and PHP Include
Your Ad Here

Banner Rotation and PHP Include


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.



Author's URL: Kyscorp.com
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Add comments to "Banner Rotation and PHP Include"

Only registered users can write comment

Reader's comments