please i need AdSense Revenue Sharing php code ?

Discussion in 'PHP' started by Mr.only, Dec 25, 2010.

  1. #1
    i need AdSense Revenue Sharing php code ?

    please i need php script to share 2 adsense accounts on my site

    somthing give 50/50 or 60/40 or ..

    me and my friend create a site and we want use adsense revenue sharing

    so we need a php code to do that

    can anyone help us
     
    Mr.only, Dec 25, 2010 IP
  2. ProxyFreak

    ProxyFreak Peon

    Messages:
    57
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Create a table in a MySQL database and add the two PUB-ID.

    then do a query on the page you are wanting to do a random pull of the publisher id's.

    $result = mysql_query("SELECT * FROM tablename order by RAND()");
    $fields = mysql_fetch_array($result);
    $google = $fields['google'];

    Add $google to the adsense code like so.

    google_ad_client = "<? echo $google; ?>";

    Publisher ID's will now be random on page loads 50/50.
     
    ProxyFreak, Dec 25, 2010 IP
  3. Mr.only

    Mr.only Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanxxxx alot ..

    can i change 50/50 to 70/30 >> ???
     
    Mr.only, Dec 26, 2010 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    You will need to use old style google ads, otherwise you will have a problem with ad slots, ie: your adsense code wont match your friends ad_slot code

    Anyway heres an easy way to achive what you want:

    
    <?php
    $random_number = mt_rand(1,10);
    if (($random_number >= 1) && ($random_number < 7)) { //gets 1-7 for 70%
    $adsense = 'your_adsense_code';
    $final_adsense = preg_replace('#google_ad_client = "(.*?)";#','google_ad_client = "pub-'.$adsense.'";',$final_adsense);
    echo $final_adsense;
    }
    if (($random_number >= 8) && ($random_number < 10)) { //gets 8,9, and 10 for 30%
    $adsense = 'your_friends_adsense_code';
    $final_adsense = preg_replace('#google_ad_client = "(.*?)";#','google_ad_client = "pub-'.$adsense.'";',$final_adsense); 
    echo $final_adsense;
    }
    ?>
    
    PHP:
    Paste the ads with your adsense code or your friends, it doesn't matter, the code above will will do the work and switch between publishers id's
     
    Last edited: Dec 26, 2010
    MyVodaFone, Dec 26, 2010 IP
  5. Mr.only

    Mr.only Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thank you so much MyVodaFone

    can you please give me full code .. ( ads code.. )

    using this id's .. please


    Ex
    my friend id: pub-0917705331920855 and i want give him 70 %

    and my id : pub-0564646461415825 and give me 30 %

    thanxx again ..
     
    Mr.only, Dec 26, 2010 IP
  6. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #6
    I did ? http://www.hooverwebdesign.com/articles/old-google-adsense-codes.html

    
    <?php
    $random_number = mt_rand(1,10);
    if (($random_number >= 1) && ($random_number < 7)) { //gets 1-7 for 70%
    $adsense = '0917705331920855';
    $final_adsense = preg_replace('#google_ad_client = "(.*?)";#','google_ad_client = "pub-'.$adsense.'";',$final_adsense);
    echo $final_adsense;
    }
    if (($random_number >= 8) && ($random_number < 10)) { //gets 8,9, and 10 for 30%
    $adsense = '0564646461415825';
    $final_adsense = preg_replace('#google_ad_client = "(.*?)";#','google_ad_client = "pub-'.$adsense.'";',$final_adsense);
    echo $final_adsense;
    }
    ?>
    
    PHP:
    Old style google ads
    <script type="text/javascript"><!--
    google_ad_client = "pub-0564646461415825";
    google_ad_width = 468;
    google_ad_height = 60;
    google_ad_format = "468x60_as";
    google_ad_type = "text";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_text = "000000";
    google_color_url = "008000";
    //--></script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    Code (markup):
     
    MyVodaFone, Dec 26, 2010 IP
  7. Mr.only

    Mr.only Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanxxx again MyVodaFone

    but can you tell me what exactly "google_ad_client" to make it work 70% for my friend and 30 % for me ..
    <script type="text/javascript"><!--
    google_ad_client = "[COLOR="darkred"]**********[/COLOR]";
    google_ad_width = 468;
    google_ad_height = 60;
    google_ad_format = "468x60_as";
    google_ad_type = "text";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_text = "000000";
    google_color_url = "008000";
    //--></script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    Code (markup):
    is it $adsense or $final_adsense; or what ?..

    and How can i test it ?

    sorry .. this is my frist time try this ..
     
    Mr.only, Dec 26, 2010 IP
  8. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #8
    You don't change the google code, the script will do that, you need only alter the colors

    $random_number = mt_rand(1,10); will generate a number between 1 and 10, if you consider each number to be 10% pending on which number is generated the script will alter the adsense code with the correct number. The first part of the code covers numbers 1-7 which would be in theory 70% and the second part, numbers 8,9 and 10 which is 3 numbers so thats 30%

    To test the script and adsense code paste the following code into a test.php file, then refresh the page and view its source code, you will see the publishers id will change 70% of the time (in theory)

    
    <?php
    $random_number = mt_rand(1,10);
    
    if (($random_number >= 1) && ($random_number < 7)) { //gets 1-7 for 70%
    $final_adsense = preg_replace('#google_ad_client = "(.*?)";#','google_ad_client = "pub-0917705331920855";',$final_adsense);
    echo $final_adsense;
    }
    
    if (($random_number >= 8) && ($random_number < 10)) { //gets 8,9, and 10 for 30%
    $final_adsense = preg_replace('#google_ad_client = "(.*?)";#','google_ad_client = "pub-0564646461415825";',$final_adsense);
    echo $final_adsense;
    }
    ?>
    
    <script type="text/javascript"><!--
    google_ad_client = "pub-0564646461415825";
    google_ad_width = 468;
    google_ad_height = 60;
    google_ad_format = "468x60_as";
    google_ad_type = "text";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_text = "000000";
    google_color_url = "008000";
    //--></script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    
    Code (markup):
     
    Last edited: Dec 26, 2010
    MyVodaFone, Dec 26, 2010 IP
  9. Mr.only

    Mr.only Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    i post the same code above in this test page.. but the publishers id never change ..

    utool.0fees.net/test.php

    please check it and tell me what is the problem ..

    and thank you soooooo much ..
     
    Last edited: Dec 26, 2010
    Mr.only, Dec 26, 2010 IP
  10. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #10
    it helps if you know what your doing, if not just asks
     
    MyVodaFone, Dec 26, 2010 IP
  11. Mr.only

    Mr.only Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    thank you brother
     
    Mr.only, Dec 26, 2010 IP
  12. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #12
    This should work...
    
    <?php
    $random_number = mt_rand(1,10);
    
    if (($random_number >= 1) && ($random_number < 7)) { //gets 1-7 for 70%
    $final_adsense = "pub-0917705331920855";
    }
    
    if (($random_number >= 8) && ($random_number < 10)) { //gets 8,9, and 10 for 30%
    $final_adsense = "pub-0564646461415825";
    }
    ?>
    
    <script type="text/javascript"><!--
    google_ad_client = "<?=$final_adsense?>";
    google_ad_width = 468;
    google_ad_height = 60;
    google_ad_format = "468x60_as";
    google_ad_type = "text";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_text = "000000";
    google_color_url = "008000";
    //--></script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    
    Code (markup):
     
    MyVodaFone, Dec 27, 2010 IP
  13. Mr.only

    Mr.only Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    yesssssssssss .. thanxxx a lot .. it's work
    but ther is simple problem ..
    the result of the test :
    7 time for google_ad_client ="pub-0917705331920855";
    1 time for google_ad_client ="pub-0564646461415825";
    1 time google_ad_client = "";

    check it here ..:
    utool.0fees.net/test2.php

    I do not know how to thank you for all you did for me
     
    Mr.only, Dec 27, 2010 IP
  14. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #14
    Last try...

    
    <?php
    $random_number = mt_rand(1,10);
    
    if (($random_number >= 1) && ($random_number < 8)) { //gets 1-7 for 70%
    $final_adsense = "pub-0917705331920855";
    }
    
    if (($random_number >= 8) && ($random_number < 11)) { //gets 8,9, and 10 for 30%
    $final_adsense = "pub-0564646461415825";
    }
    ?>
    
    <script type="text/javascript"><!--
    google_ad_client = "<?=$final_adsense?>";
    google_ad_width = 468;
    google_ad_height = 60;
    google_ad_format = "468x60_as";
    google_ad_type = "text";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_text = "000000";
    google_color_url = "008000";
    //--></script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    
    PHP:
     
    MyVodaFone, Dec 27, 2010 IP
  15. Mr.only

    Mr.only Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    The problem is resolved .. Thank you very much

    But I can't be sure that the ratio

    Is it 70% and 30%

    check it now here : utool.0fees.net/test2.php
     
    Mr.only, Dec 27, 2010 IP