Saturday, June 14, 2008

Create a Rotating Ads

If you run more than one ads, but lack of space to put the ads, you can actually rotate the ads.

The code below will create a random number from 1 to 10. Since I want both ads to be shown with a probability of 50%, I put the condition if (x > 5). However, you can change this number.

<?php $x = rand(1,10); ?>
<?php if ($x > 5) { ?>

<!--your first ad code-->

<?php } else {?>

<!--your second ad code-->

<?php } ?>
You can read more about PHP rand() function here.