Simple Rotating Ad Script in PHP

Date: 7 Feb 2010 Comments: 0

This weekend I sold banner ad space in one of my websites. The client wanted two banners to be rotated in same place. Here’s a simple php script how it can be done:
<a href=”http://advertise-site-url.com” target=”_blank”>
<?php
$variable[1] = ‘<img src=”http://www.mysite.com/ads/banner-1.jpg” alt=”banner 1″ />’;
$variable[2] =’<img src=”http://www.mysite.com/ads/banner-2.jpg” alt=”banner 2″ />’;

$adCount = count($variable);
$randomAdNumber = mt_rand(1, $adCount);
echo $variable[$randomAdNumber];
?>
</a>

That’s really all. You can rotated as much as you want ads, just need to add new $variable[number] line with banner html code.

Leave a Reply


Spam protection by WP Captcha-Free