PHP Ads Rotator

richarab

Junior Member
Joined
Sep 18, 2008
Messages
147
Reaction score
23
I have a website, I have an iframe on the website. I want to be able to rotate different ads/sites/ on the iframe. The Iframe redirects to a php file. I need to be able to place a shit load of ads into that file and have it rotate in my Iframe. can anyone help?
 
Edited By Moderator: Forum Promotion Not Allowed
 
Last edited by a moderator:
Heres a basic script I use. I'm currently looking for the more advanced one that can be scaled.

PHP:
      <?php

      $number = rand(1,3);

       
 
      switch ($number){

              case 1:

                      echo ‘Adsense code';

                      break;

              case 2:

                      echo ‘Adbrite code';

                      break;

              case 3:

                      echo ‘Zango code';

                      break;
 
      }
  
      ?>
 
Here is a quick one that should work for you. Place all your ads in a file called ads.txt with each ad separated by a string like ----- eg
ads.txt
ad1
-----
ad2
ad2
-----
ad3
ad3
ad3
-----
ad4
ad4
ad4
ad4
-----
ad5
ad5
ad5
ad5
ad5
Then the php file for your iframe should be as simple as this
myads.php
PHP:
<?php
   $adsFileContents = file_get_contents('ads.txt');
   $ads = explode('-----',$adsFileContents);
   echo $ads[array_rand($ads)];
?>
 
Found it!!!!! This one can be scaled easily.

PHP:
<?php
//Add as many links you want
$mylink[1] = '<a href="http://www.pegor.com">Free PHP Tutorials</a>';
$mylink[2] = '<a href="http://www.lifestinks.info">Fast Facebook Proxy</a>';
$mylink[3] = '<a href="http://www.mozilla.org">Fastest and Secure Web Browser</a>';
//$mylink[4] = .....
//$mylink[5] = ....

// this will count your links itself and select a random one
$id = rand(1,count($mylink));

// this will display the random link
echo $mylink[$id];
?>
 
Found it!!!!! This one can be scaled easily.
You could remove the little extra number keeping headache
PHP:
<?php
//Add as many links you want
$mylink[] = '<a href="http://www.pegor.com">Free PHP Tutorials</a>';
$mylink[] = '<a href="http://www.lifestinks.info">Fast Facebook Proxy</a>';
$mylink[] = '<a href="http://www.mozilla.org">Fastest and Secure Web Browser</a>';
//$mylink[] = .....
//$mylink[] = ....

// this will display the random link
echo $mylink[array_rand($mylink)];
?>
 
I notice these are text links, can you put in image links also?
 
You can put anything inside the single quotes, including javascript.
 
couldn't you do it with openx as well?

Yes you can, but I guess that would be too much for the OP to handle. When and if his needs ever require something like openx, his question will be different.
 
Back
Top