PHP Script to Rotate Between Ads

Discussion in 'PHP' started by kschill, Mar 30, 2006.

  1. #1
    Here's to hoping someone can lend a helping hand :eek:

    I'm aware of shoemoney's code which rotates YPN and Adsense on your pages, however, when I add this php script in multiple spaces on one page sometimes I get one ad displaying YPN and the other Adsense. Is there any script that displays one or the other when coding for multiple spaces/places on your site?

    Hope this makes sense.....
     
    kschill, Mar 30, 2006 IP
  2. Psychotomus

    Psychotomus Guest

    Messages:
    427
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    do you want it to take turns or one to apear randomly?


    $randNum = mt_rand(1, 2);

    if ($randNum == 1)
    {
    print 'google ads';
    }
    else
    {
    print ' Yahoo ads';
    }

    displays random google or yahoo ads
     
    Psychotomus, Mar 30, 2006 IP
  3. kschill

    kschill Well-Known Member

    Messages:
    359
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    108
    #3
    I need them to take turns. So if i had a three column site and 1 ad in the left column and a second ad in the right column they can't display google ads and yahoo ads at the same time b/c its against TOS. Both of them have to be one or the other.
     
    kschill, Mar 30, 2006 IP
  4. Psychotomus

    Psychotomus Guest

    Messages:
    427
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This will display one or the other.
     
    Psychotomus, Mar 30, 2006 IP
  5. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #5
    you have to put Psychotomus code somewhere in in your code before you write the first add into your page.

    
    function rndads() {
    $randNum = mt_rand(1, 2);
    
    if ($randNum == 1)
    {
    return '<google html adcode goes here>';
    }
    else
    {
    return '<put your yahoo adcode in here>';
    }
    }
    
    PHP:
    the you just write the adcode in a $var

    
    $adcode=rndads();
    
    PHP:
    and insert <?=$adcode;?> whereever you need it - so you always have only google or yahoo ads on a page.
     
    falcondriver, Mar 30, 2006 IP