Login to Google AdSense using PHP
« Freshen your Anti-virus, Anti-Rootkits, and Anti-SpywareApache HTTPD Google CSE »
Here is an example demonstrating the power of cURL. This code posts all the correct post fields to Googles universal Account Services login and brings the user directly to the AdSense Overview page. Cookies are used in this example as well as setting the USER AGENT and REFERRER HTTP headers.
<?php
/* "AdSense totals sent via SMS to cellphone"
http://www.webmasterworld.com/forum89/5349.htm
"Follow your Adsense earnings with an RSS reader"
http://curl.askapache.com/libcurl/php/examples/rss-adsense.html
"Auto-Login to Google Analytics to impress Clients"
http://www.askapache.com/webmaster/login-google-analytics.html */
// Uncomment to only allow from IP 1.1.1.1
// if($_SERVER['REMOTE_ADDR'] !== '1.1.1.1') die();
$username=urlencode('myemail@gmail.com');
$password="mypassword";
$gacookie="./.gacookie";
$postdata="Email=$username&Passwd=$password&GA3T=5AS_gBsvDHI&nui=15&fpui=3&askapache=http://www.askapache.com/"
."&service=adsense&ifr=true&rm=hide&itmpl=true&hl=en_US&alwf=true&continue=https://www.google.com/adsense/report/overview&null=Sign in";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,"https://www.google.com/accounts/ServiceLoginBoxAuth");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $gacookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $gacookie);
curl_setopt ($ch, CURLOPT_REFERER, 'https://www.google.com/adsense/report/overview');
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$AskApache_result = curl_exec ($ch);
curl_close($ch);
echo $AskApache_result;
unlink($gacookie);
exit;
?>
« Freshen your Anti-virus, Anti-Rootkits, and Anti-Spyware
Apache HTTPD Google CSE »
Please consider donating to support active development of the free software and articles here.![]()
The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect. Tim Berners-Lee
It's very simple - you read the protocol and write the code. -Bill Joy
HTML | DCMI | GRDDL | XOXO | XDMP | XFN | DOM | XML | XHTML 1.1 Strict | CSS 2.1 | W3C | TLDP | WAI | DISA | ICSI | GIAC | SANS RR | GHOST | DEFCON | NIST | DHS CYBER | NIST | .:: Phrack Magazine ::.
↑ TOPExcept where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. HTTPD based on NCSA HTTPd
Hi ,
I have a question on how you assigned the cookies.I tried looking them up in LiveHTTP headers but I could not find the
part in the above code.I’d be grateful if you could explain it a bit please.Thanks