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
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.
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
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 ..
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):
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 ..
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):
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 ..
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):
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
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:
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