Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 423

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 423

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 426

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/templates/ja_purity/ja_templatetools.php on line 49
Ads rotation in php - The Scripts Library Community

Free Programming Tutorials & Source Code

 
  • Increase font size
  • Default font size
  • Decrease font size
Home PHP Ads rotation in php

Ads rotation in php

E-mail
(4 votes, average: 4.50 out of 5)
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!