1. <?php
  2. function getMoneyGoogleAdsense($sLogin, $sPass, $cookiePath='cookie.txt')
  3. {
  4. $cookie_file = dirname(__FILE__) . '/'.$cookiePath;
  5. $c = curl_init('https://www.google.com/adsense/');
  6. curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_file);
  7. curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_file);
  8. curl_setopt($c, CURLOPT_URL, 'https://www.google.com/adsense/');
  9. curl_setopt($c, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
  10. curl_setopt($c, CURLOPT_POST, 1);
  11. curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
  12. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  13. curl_getinfo($c);
  14. $s = curl_exec($c);
  15. curl_close($c);
  16. $sLink = preg_replace('!.*<A HREF="(.*?)".*!is', '$1', $s);
  17.  
  18.  
  19. $c = curl_init('https://www.google.com/adsense/');
  20. curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_file);
  21. curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_file);
  22. curl_setopt($c, CURLOPT_URL, 'https://www.google.com'.$sLink);
  23. curl_setopt($c, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
  24. curl_setopt($c, CURLOPT_POST, 1);
  25. curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
  26. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  27. curl_getinfo($c);
  28. $s = curl_exec($c);
  29. curl_close($c);
  30. $sLink = preg_replace('!.*<A HREF="(.*?)".*!is', '$1', $s);
  31.  
  32. $c = curl_init('https://www.google.com/adsense/');
  33. curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_file);
  34. curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_file);
  35. curl_setopt($c, CURLOPT_URL, 'https://www.google.com'.$sLink);
  36. curl_setopt($c, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
  37. curl_setopt($c, CURLOPT_POST, 1);
  38. curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
  39. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  40. curl_getinfo($c);
  41. $s = curl_exec($c);
  42. curl_close($c);
  43. $sLink = preg_replace('!.*<A HREF="(.*?)".*!is', '$1', $s);
  44.  
  45. $c = curl_init('https://www.google.com/adsense/');
  46. curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_file);
  47. curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_file);
  48. curl_setopt($c, CURLOPT_URL, 'https://www.google.com'.$sLink);
  49. curl_setopt($c, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
  50. curl_setopt($c, CURLOPT_POST, 1);
  51. curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
  52. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  53. curl_getinfo($c);
  54. $s = curl_exec($c);
  55. curl_close($c);
  56. $sLink = preg_replace('!.*<A HREF="(.*?)".*!is', '$1', $s);
  57.  
  58. $c = curl_init('https://www.google.com/adsense/');
  59. curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_file);
  60. curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_file);
  61. curl_setopt($c, CURLOPT_URL, 'https://www.google.com/accounts/ServiceLoginBoxAuth');
  62. curl_setopt($c, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
  63. curl_setopt($c, CURLOPT_POST, 1);
  64. curl_setopt($c, CURLOPT_POSTFIELDS,
  65. 'continue=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth&followup=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth&service=adsense&nui=15&fpui=3&ifr=true&rm=hide&ltmpl=login&hl=pl&alwf=true&GA3T=1hXNw5FJHzY&GALX=CChwX7HQKf8&Email='.$sLogin.'&Passwd='.urlencode($sPass));
  66. curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
  67. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  68. curl_getinfo($c);
  69. $s = curl_exec($c);
  70. curl_close($c);
  71.  
  72. $sLink = preg_replace('!.*<noscript>.*<a href="(.*)" target="_top">.*</noscript>!is', '$1', $s);
  73.  
  74. $c = curl_init('https://www.google.com/accounts/ServiceLoginBoxAuth');
  75. curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_file);
  76. curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_file);
  77. curl_setopt($c, CURLOPT_URL, 'https://www.google.com/accounts/CheckCookie?continue=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth&followup=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth&service=adsense&hl=pl&chtml=LoginDoneHtml');
  78. curl_setopt($c, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
  79. curl_setopt($c, CURLOPT_POST, 1);
  80. curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
  81. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  82. curl_getinfo($c);
  83. $s = curl_exec($c);
  84. curl_close($c);
  85.  
  86. $sLink = str_replace('&', '&', preg_replace('!.*<meta http-equiv="refresh" content="0; url='(.+)'">.*!is', '$1', $s));
  87.  
  88. $c = curl_init('https://www.google.com/accounts/CheckCookie?continue=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth&followup=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth&service=adsense&hl=pl&chtml=LoginDoneHtml');
  89. curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_file);
  90. curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_file);
  91. curl_setopt($c, CURLOPT_URL, $sLink);
  92. curl_setopt($c, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
  93. curl_setopt($c, CURLOPT_POST, 1);
  94. curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
  95. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  96. curl_getinfo($c);
  97. $s = curl_exec($c);
  98. curl_close($c);
  99.  
  100. $c = curl_init($sLink);
  101. $sLink = preg_replace('!.*<A HREF="(.*?)".*!is', '$1', $s);
  102. curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_file);
  103. curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_file);
  104. curl_setopt($c, CURLOPT_URL, $sLink);
  105. curl_setopt($c, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
  106. curl_setopt($c, CURLOPT_POST, 1);
  107. curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
  108. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  109. curl_getinfo($c);
  110. $s = curl_exec($c);
  111. curl_close($c);
  112.  
  113. $c = curl_init($sLink);
  114. $sLink = preg_replace('!.*<A HREF="(.*?)".*!is', '$1', $s);
  115. curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_file);
  116. curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_file);
  117. curl_setopt($c, CURLOPT_URL, 'https://www.google.com'.$sLink);
  118. curl_setopt($c, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
  119. curl_setopt($c, CURLOPT_POST, 1);
  120. curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
  121. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  122. curl_getinfo($c);
  123. $s = curl_exec($c);
  124. curl_close($c);
  125.  
  126. $c = curl_init($sLink);
  127. $sLink = preg_replace('!.*<A HREF="(.*?)".*!is', '$1', $s);
  128. curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_file);
  129. curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_file);
  130. curl_setopt($c, CURLOPT_URL, 'https://www.google.com'.$sLink);
  131. curl_setopt($c, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
  132. curl_setopt($c, CURLOPT_POST, 1);
  133. curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
  134. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  135. curl_getinfo($c);
  136. $s = curl_exec($c);
  137. curl_close($c);
  138.  
  139. $c = curl_init('https://www.google.com/adsense/report/overview');
  140. $sLink = preg_replace('!.*<A HREF="(.*?)".*!is', '$1', $s);
  141. curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_file);
  142. curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_file);
  143. curl_setopt($c, CURLOPT_URL, 'https://www.google.com/adsense/report/overview?timePeriod=alltime');
  144. curl_setopt($c, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
  145. curl_setopt($c, CURLOPT_POST, 1);
  146. curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
  147. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  148. curl_getinfo($c);
  149. $s = curl_exec($c);
  150. curl_close($c);
  151.  
  152. $sMoney = preg_replace('!.*Razem dochody</td>.*?<td style="font-weight:bold;" nowrap>([0-9,]+) US$.*!is', '$1', $s);
  153. return $sMoney;
  154. }
  155. ?>


I przyk³ad u¿ycia:
  1. <?php
  2. $sLogin = '****'; //bez @gmail.com
  3. $sPass = '******';
  4.  
  5. $sCache = 'money.cache';
  6. $iPeriod = 3600*24;
  7. if(file_exists($sCache) AND filemtime($sCache)>=(time()-$iPeriod))
  8. {
  9. header("Content-type: image/png");
  10. $image = file_get_contents($sCache);
  11. echo $image;
  12. } else {
  13. $ileNaKoncie = getMoneyGoogleAdsense($sLogin, $sPass);
  14.  
  15. $ilePotrzeba = 100;
  16. $value = '$';
  17. $percent = ($ileNaKoncie/$ilePotrzeba)*100;
  18. $im = imagecreatetruecolor(148, 40);
  19. $color = imagecolorallocatealpha($im, 255, 255, 255, 0);
  20. $black = imagecolorallocate($im, 0, 0, 0);
  21. imagefillalpha($im, $color);
  22. if(isset($percent))
  23. {
  24. if($percent<=50)
  25. {
  26. $iGreen = ($percent==50)?255:((int)$percent*5);
  27. $color_percent = imagecolorallocate($im,255,$iGreen,0);
  28. }
  29. elseif($percent>50)
  30. {
  31. $iGreen = ($percent==51)?251:502-($percent*5)-1;
  32. $color_percent = imagecolorallocate($im,$iGreen,255,0);
  33. }
  34. }
  35. imagefilledrectangle($im, 24, 0, $percent+24, 12, $color_percent);
  36. imagestring($im, 2, 67, 0, round($percent).'%', $black);
  37. imagerectangle($im, 24, 0, 124, 12, $black);
  38. imagestring($im, 2, 5, 15, ''.$ileNaKoncie.$value.' z '.$ilePotrzeba.$value.' potrzebnych', $black);
  39. header("Content-type: image/png");
  40. imagesavealpha($im);
  41. imagepng($im, $sCache);
  42. imagepng($im);
  43. imagedestroy($im);
  44. }
  45. function ImageFillAlpha($image, $color)
  46. {
  47. imagefilledrectangle($image, 0, 0, imagesx($image), imagesy($image), $color);
  48. }
  49. ?>


I wygl±da to tak: