1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simple banner rotation script

Discussion in 'Programming' started by tony84, May 28, 2007.

  1. #1
    I want a script that can display google ads, and linkable images on a rotator when a page is refreshed.

    I dont want it to be database driven and i dont want ti to be in javascript.

    I also dont want it on a timer.

    I know thats a lot of dont wants but id really appreciate any help
     
    tony84, May 28, 2007 IP
  2. JFS

    JFS Active Member

    Messages:
    222
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #2
    this is a simple one:

    
    <?php
    $a="<a href='link'><img src='image.jpg' align='center'></a>";
    $b="<a href='link2'><img src='image2.jpg' align='center'></a>";
    
    srand( microtime() * 1000000);
    $var = rand(1,2);
    switch($var){
    
    case 1: $ads=$a;
    	break;
    case 2: $ads=$b;
    	break;
                }
    echo $ads;
    
    
    Code (markup):
    to put adsense in the above change the " into '
     
    JFS, May 28, 2007 IP
  3. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #3
    i know this is fairly simpl but i once had a script which i cant find aymore and it was much simpler than this
     
    tony84, May 28, 2007 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    For the .Net version

    code:
    <asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="ad.xml" />

    ad.xml file:
    <Advertisements>
    <Ad>
    <ImageUrl>site1img1.jpg</ImageUrl>
    <NavigateUrl>http://www.site1.com</NavigateUrl>
    <Impressions>50</Impressions>
    </Ad>
    <Ad>
    <ImageUrl>site2img2.jpg</ImageUrl>
    <NavigateUrl>http://www.site2.com</NavigateUrl>
    <Impressions>75</Impressions>
    </Ad>
    </Advertisements>

    Impressions is the relative weightings so in this example ad2 would be shown 1.5 times more often
     
    AstarothSolutions, May 29, 2007 IP
  5. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #5
    i dont have asp, ive settled for a script that can use javascript however it needs to be able to accept google adsense, cheers for any help
     
    tony84, May 30, 2007 IP
  6. ryanjparker

    ryanjparker Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    In the original post you say you don't want JavaScript, but now you say you'll settle for JavaScript? Which one is it? What language is running your website? HTML, PHP, Perl...?
     
    ryanjparker, May 30, 2007 IP
  7. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #7
    html and php, and i changed my mind because originally i didt want js as a lot of people have it disabled, however now i realise that adsense actually uses js so it doesnt really matter
     
    tony84, May 31, 2007 IP
  8. ryanjparker

    ryanjparker Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    JFS's code looks about right (similar to something I wrote)
     
    ryanjparker, May 31, 2007 IP
  9. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #9
    how would i edit that in order for it to have adsense?
    do i change all of <a href='link'><img src='image.jpg' align='center'></a> to my adsense cod or everything but the a href and /a?
     
    tony84, May 31, 2007 IP
  10. ryanjparker

    ryanjparker Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Basically you want to set the $a and $b variables to be the actual code you want to be displayed. In this case he simply has links, but you can change this to AdSense or whatever code you want.
     
    ryanjparker, May 31, 2007 IP
  11. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #11
    i promise im not being lazy im just really not good wth code

    could you please put this where it needs to be for both of the different adsense accounts please?
    <script type="text/javascript"><!--
    google_ad_client = "pub-00000000";
    google_ad_width = 728;
    google_ad_height = 90;
    google_ad_format = "728x90_as";
    google_ad_type = "text";
    google_ad_channel = "";
    google_color_border = "666666";
    google_color_bg = "666666";
    google_color_link = "ffffff";
    google_color_text = "ffffff";
    google_color_url = "f29935";
    //-->

    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
     
    tony84, May 31, 2007 IP
  12. ryanjparker

    ryanjparker Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    You need to place that code inside of the variable, but be sure to escape the ". If you're not sure how to do that then search Google. ;)
     
    ryanjparker, Jun 1, 2007 IP
  13. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #13
    ive tried it, it shows the first adsense, but when i refresh it doesnt hve the secod lot :s

    this is the code i was using, i jus put it in a simple page 1st
    <html>
    <head></head><body><?php
    $a="<script type="text/javascript"><!--
    google_ad_client = "pub-00000000";
    google_ad_width = 728;
    google_ad_height = 90;
    google_ad_format = "728x90_as";
    google_ad_type = "text";
    google_ad_channel = "";
    google_color_border = "666666";
    google_color_bg = "666666";
    google_color_link = "ffffff";
    google_color_text = "ffffff";
    google_color_url = "f29935";
    //-->
    
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>";
    $b="<script type="text/javascript"><!--
    google_ad_client = "pub-00000022200";
    google_ad_width = 728;
    google_ad_height = 90;
    google_ad_format = "728x90_as";
    google_ad_type = "text";
    google_ad_channel = "";
    google_color_border = "666666";
    google_color_bg = "666666";
    google_color_link = "ffffff";
    google_color_text = "ffffff";
    google_color_url = "f29935";
    //-->
    
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>";
    
    srand( microtime() * 1000000);
    $var = rand(1,2);
    switch($var){
    
    case 1: $ads=$a;
    	break;
    case 2: $ads=$b;
    	break;
                }
    echo $ads;
    </body></html>
    PHP:
     
    tony84, Jun 2, 2007 IP
  14. champ_rock

    champ_rock Peon

    Messages:
    3,349
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #14
    the code simply selects a random ad and by chance when u refreshed it selected the same ad again

    try refreshing it more. it is based on a probability and if u refresh 100 times and record ur observations then it will come to around 50-50 each..

    it is NOT EXACT 50%

    ------------

    also i think u forgot to close the php at the end .. place this ?>
     
    champ_rock, Jun 2, 2007 IP
  15. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #15
    i refreshed around 8-10 times
     
    tony84, Jun 2, 2007 IP
  16. champ_rock

    champ_rock Peon

    Messages:
    3,349
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #16
    ok sorry i did not look at the code earlier. i am posting this code now. this should work

    <html>
    <head></head><body><?php
    $a='<script type="text/javascript"><!--
    google_ad_client = "pub-00000000";
    google_ad_width = 728;
    google_ad_height = 90;
    google_ad_format = "728x90_as";
    google_ad_type = "text";
    google_ad_channel = "";
    google_color_border = "666666";
    google_color_bg = "666666";
    google_color_link = "ffffff";
    google_color_text = "ffffff";
    google_color_url = "f29935";
    //-->
    
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>';
    $b='<script type="text/javascript"><!--
    google_ad_client = "pub-00000022200";
    google_ad_width = 728;
    google_ad_height = 90;
    google_ad_format = "728x90_as";
    google_ad_type = "text";
    google_ad_channel = "";
    google_color_border = "666666";
    google_color_bg = "666666";
    google_color_link = "ffffff";
    google_color_text = "ffffff";
    google_color_url = "f29935";
    //-->
    
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>';
    
    srand( microtime() * 1000000);
    $var = rand(1,2);
    switch($var){
    
    case 1: $ads=$a;
        break;
    case 2: $ads=$b;
        break;
                }
    echo $ads;
    ?>
    </body></html> 
    
    Code (markup):
     
    champ_rock, Jun 2, 2007 IP
    gemini181 likes this.
  17. GMROCKS

    GMROCKS Active Member

    Messages:
    648
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #17
    MAJOR MISTAKE IN YOUR CODE:

    you have to escape your quotes.

    ex: I want to take <font color="blue"> and put that into a javascript string.
    I would make it into:
    $a="<font color='blue'>";
    so I would take my double quotes and make them into single quotes.
     
    GMROCKS, Jun 2, 2007 IP
  18. champ_rock

    champ_rock Peon

    Messages:
    3,349
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #18
    i do not think ur code will work because javascript will take ' and " differently.

    in the above code that i have posted i have rectified the error because php takes " and ' same
     
    champ_rock, Jun 2, 2007 IP
  19. GMROCKS

    GMROCKS Active Member

    Messages:
    648
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #19
    I was looking in the wrong area- my bad

    instead of replacing quotes with ' try /" and it should escape them. it might be \" though, I can't remember which way is which. pretty sure it's the right one.
     
    GMROCKS, Jun 2, 2007 IP
  20. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #20
    im confused? Im really not a coder, up until now id got by with html, basic css and php include
     
    tony84, Jun 2, 2007 IP