I cobbled up a little PHP script to rotate amazon ads. The ads are each kept in a separate file in the same folder. It does not matter whether the ad code is on one line or multiple, the script reads it into a single string.
amazon_puller.php
PHP Code:
<?php
$ads = array();
if ($handle = opendir("$path_ads/$folder"))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
//echo "$file<br>";
array_push($ads, "$file");
}
}
closedir($handle);
}
srand((float) microtime() * 10000000);
//print_r($ads);
$rand_keys = array_rand($ads, 2);
$ad_show = $ads[$rand_keys[0]];
echo file_get_contents("$path_ads/$folder/$ad_show");
echo '<br>';
?>
The ads is called like so:
PHP Code:
<?php
$folder='amazon_books';
include("$path_includes/amazon_puller.php");a?>
this is the CSS used to center that ads, just ad it to your css file. If you use iframes elsewhere in your site just turn the code into a pseudo class(iframe.ads) and use it as class=ads inside the iframe.
Code:
iframe {
display: block;
margin-left: auto;
margin-right: auto
}
Of course you will have to pull paths from your own config file or hard code them into the script. The nice thing is by using the $folder var in the call you can use the same script to serve whatever ad(s) you want on whatever page(s). It is also trivial to hack it so it displays more than one ads.
If you try using it and run into problems just yell and I'll point you in the right direction.
Enjoy,
.