Total Members: 48

Who's online

There are currently 1 user and 0 guests online.

Ads rotation in php

A simple script that allows you to define three ads, and display them based on a specified ratio.
First, let's define each ads ratio. We want 70% for the first one, 20% for the second one, and 10% for the third one.
Thus, we have to declare a number number that varies between 1 and 100

// random number 1 - 100
$result_random=rand(1, 100);

check the result of result_random; if it's less of equal 70, show ad 1:

// if result less than or equal 70, display ad 1 (70%)
if($result_random<=70){
// show ad
echo "Ad 1 banner";
}

If the result is less than or equal 90, show ad 2:

// if result less than or equal 90, display ad 2 (20%)
elseif($result_random<=90){
// show ad
echo "Ad 2 banner";
}

If the result is less than or equal 100, show ad 3:

// if result less than or equal 100, display ad 3 (10%)
elseif($result_random<=100){
// show ad
echo "Ad 3 banner";
}

That's it!