First, create a file with a name like adverts.php and have this at the top:
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 quote mark, like this: \"
$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 advertisement. This may seem like a stupid feature for a random advert generator, but it could happen if you drop non-performing affiliates or if paid-inclusion ads expire.)
$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>";
?>