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 adsense rotator script?

Discussion in 'Programming' started by maney, Oct 4, 2006.

  1. #1
    I'm looking for a simple script which will rotate my ads. I've tried a few I found searching the internet or these forums but none of been what I have been looking for. Some of them haven't liked javascript in javascript (the google ads was JS, as was the rotator) and some have only been for banners or text links.

    All I am after is a simple bit of code I can put in which will randomly change the adsense code (its all link units, I'm just varying the colour) on a page refresh. Doesn't have to be fancy or do any tricks. I just want it to rotate the ads.

    Can anbody make any recomendations?

    Thanks

    Dan
     
    maney, Oct 4, 2006 IP
  2. fordP

    fordP Peon

    Messages:
    548
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Many of the banner rotators have you just insert html/text. IF you find one like this you could use it as an adsense code rotator / or simple revenue sharing script
     
    fordP, Oct 5, 2006 IP
  3. surfnearnzone

    surfnearnzone Well-Known Member

    Messages:
    1,492
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #3
    What exactly do you want? Will you pay for it? :)
     
    surfnearnzone, Oct 5, 2006 IP
  4. kartik786

    kartik786 Well-Known Member

    Messages:
    1,904
    Likes Received:
    60
    Best Answers:
    0
    Trophy Points:
    170
    #4
    Phpadsnew rocks.

    I can help you to install it if you want to.

    If you dont read the documentation, you will keep wondering how to use it :p
     
    kartik786, Oct 5, 2006 IP
  5. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #5
    just use Server-Side language to write out the javascriopt. create 5 strings in PHP/ASP/CF whatever... then put them strings into an array server-side. then randomize a number (from 0 to 4) and display that array's item - where the random number is the array index :) Do NOT attempt to do this with JS because it will most likely be against their TOS and will probably F up the Adsense script :) - Simple solution - just let your Serverside Script write the JS.
     
    ccoonen, Oct 5, 2006 IP
  6. maney

    maney Active Member

    Messages:
    1,130
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    90
    #6
    You've got exactly what I'm looking for, just a bit of code I can insert on to a page, but I'm no coder so I wouldn't know where to start looking for the information to chuck one together.
     
    maney, Oct 6, 2006 IP
  7. Bombaywala

    Bombaywala Peon

    Messages:
    1,249
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Rocks - maybe. I like that atleast it allows to display zillion banners without you worrying.
     
    Bombaywala, Oct 6, 2006 IP
  8. maney

    maney Active Member

    Messages:
    1,130
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    90
    #8
    I tried using phpadsnew but I got an error about my register_long_arrays.

    It also seems to be much more complex than I actually need. I just need a bit of php code which will randomly rotate some ads on a page refresh.
     
    maney, Oct 7, 2006 IP
  9. surfnearnzone

    surfnearnzone Well-Known Member

    Messages:
    1,492
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #9
    Hi,

    Once again I am here. Is this what you are looking for. :D This is in asp because i am not familliar with php.

    i had to do a lot of search on the internet(I spent 2 nights doing this:eek: ) then i had to debug it as the first three codes did'nt work.

    The code is simple but i had to spend a lot of time doing this. It really amazed me how a simple task as this would eat up so much of my time. And the most amazing thing is that it is just a two line code :eek:

    I will explain everything to you and also help in installation.

     
    surfnearnzone, Oct 7, 2006 IP
  10. surfnearnzone

    surfnearnzone Well-Known Member

    Messages:
    1,492
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #10
    I have chosen completely different layouts because i wanted them to make it distinguishable and the differences to be recognizable. However, you can choose any layout of your choice when you use them and any no. of different layouts. But i recommend to not to use more than 4-5 layouts per position as it will make ads to be repeated.
     
    surfnearnzone, Oct 7, 2006 IP
  11. Gekkie

    Gekkie Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Make a new php file for every ad and insert the adcode in it. And name them 1.php 2.php ect.

    On the place you wanna insert the ad place this code:

    
    <?php
    // If you have 5 ads
    random = rand(1, 5);
    include "$random.php";
    ?>
    
    PHP:
    This will pick a random number between 1 and 5 and includes that php file into that location.
     
    Gekkie, Oct 7, 2006 IP
  12. surfnearnzone

    surfnearnzone Well-Known Member

    Messages:
    1,492
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #12
    Have you already tested it. can i see a demo please.

     
    surfnearnzone, Oct 7, 2006 IP
  13. maney

    maney Active Member

    Messages:
    1,130
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    90
    #13
    I've tried that but it doesn't seem to want to work :(
     
    maney, Oct 8, 2006 IP
  14. surfnearnzone

    surfnearnzone Well-Known Member

    Messages:
    1,492
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #14
    :cool: somehow but i knew it won't work. it is true that i am not familiar with php but i am a kinda experienced programmer and by looking at the code i knew it wont work so i asked Gekkie for a demo.

    If you are intretsed in my code then rep me. i can perhaps make it work for you even if your host does'nt support asp :eek:

    :cool: infact i know what is the problem with the Gekkie's PHP code. the same thing happened in my similar asp code too. The code i have for asp is unique and is an inbuilt function of asp. i don't know if a similar solution exists for PHP.

    And yes i did it for money :eek: but now i feel if you were to want to spend money for it you would have had posted it in the business forum, so ...........

     
    surfnearnzone, Oct 8, 2006 IP
  15. surfnearnzone

    surfnearnzone Well-Known Member

    Messages:
    1,492
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #15
    Ok try this. i don't know if it will work but just trying my coding common sense.

    Remove the " marks and place it the way i have in this code for random.php.It should be $random.".php". and not "$random.php"

    Good luck with your code.:)

    
    <?php
    // If you have 5 ads
    random = rand(1, 5);
    include $random.".php";
    ?>
    
    PHP:
    But still i beleive an include directive will not be able to read this and it may give errors. Just try; i don't have a php account or else i would have tested it.

     
    surfnearnzone, Oct 8, 2006 IP
  16. r3dt@rget

    r3dt@rget Notable Member

    Messages:
    1,054
    Likes Received:
    64
    Best Answers:
    1
    Trophy Points:
    220
    #16
    r3dt@rget, Oct 8, 2006 IP
  17. Bombaywala

    Bombaywala Peon

    Messages:
    1,249
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #17
    In iframe - stay away from this.
     
    Bombaywala, Oct 9, 2006 IP
  18. mehbooba

    mehbooba Peon

    Messages:
    260
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #18
    this works....

    <?php

    // If you have 3 ads

    $random = rand(1, 3);

    // store the full path and filename
    $filename = "$_SERVER[DOCUMENT_ROOT]/toplevel/nextlevel/adsdirectory/$random.php";

    // get the random adsense ad
    include ("$filename");

    ?>


    NB :

    change this "/toplevel/nextlevel/adsdirectory/"

    to whatever absolute path your 1.php, 2.php....n.php are held in (eg from your top level directory to the directory where you ads are held).



    it works for me.

    if it does for you then a 'greeny' wouldnt go a miss.

    thanks
     
    mehbooba, Oct 17, 2006 IP
    picking likes this.