#native_company# #native_desc#
#native_cta#

Rotating Advertisement Script

By Bill Pellowe
on August 16, 2003

Version: 1.1

Type: Full Script

Category: File Management

License: GNU General Public License

Description: Randomly rotate your advertisements. Works without a database and without cookies. Handles banners, text-based ads, whatever format. Includes troubleshooting tips for .html files (either follow the tutorial for .htacess editing or use the JavaScript workaround). Free.

For working version, updated code and troubleshooting tips, see
http://www.i-fubar.com/rotation-ad-script.php

First, create a file with a name like adverts.php and have this at the top: 
<? 
$bannerCounter= 1; 

For each of your advertisements, you'll first write out the ad's code, and then increase the banner counter, like this: 
$bannerCode[$bannerCounter] = "put your ad code here"; 
$bannerCounter++;

For the example below, let's do a 3-banner rotation. Note that every " in your ad code needs to be "escaped" with a slash mark in front of the code. 
$bannerCode[$bannerCounter] = "<A HREF="http://www.amazon.com/exec/obidos/redirect-home/teijn21-20">
<IMG SRC="home-banner-468x60.gif" BORDER="0" HEIGHT="60" WIDTH="468" alt="In Association with Amazon.com"></A>"; 
$bannerCounter++;

$bannerCode[$bannerCounter] = "<a href="http://www.vmcsatellite.com/?aid=55537" target="_top"> <img src="http://www.vmcsatellite.com/banners/468x60(2).gif" width="468" height="60" alt="Free Satellite TV!" border="0"></a>"; 
$bannerCounter++;

$bannerCode[$bannerCounter] = "<a href="http://www.vmcsatellite.com/channels/affiliates.cfm?aid=55537" target="_top"> <img src="http://www.vmcsatellite.com/banners/recruit395x141.gif" width="395" height="141" alt="Free Satellite TV!" border="0"></a>"; 
$bannerCounter++;


Next, we get the total number of ads, and if there are more than one, we'll randomly pick one of them. (If less than one, we automatically pick the first one.) 
$bannerAdTotals = $bannerCounter - 1; 
if($bannerAdTotals>1) 
{
   mt_srand((double)microtime() * 1234567); 
   $bannerPicked = mt_rand(1, $bannerAdTotals); 
}
else
{
   $bannerPicked = 1; 
}
$bannerAd = $bannerCode[$bannerPicked]; 
?> 
That's the end of the adverts.php file.
 
Now, your webpage showing the ad first needs to include this script, then show the ad, like this: 
<? 
include_once("adverts.php"); 
echo "<div align='center'>$bannerAd</div>
?>
That's all!


For working version, updated code and troubleshooting tips, see
http://www.i-fubar.com/rotation-ad-script.php