Forum Moderators: martinibuster
$username="your-username";
$password="your-password";
$postdata="Email=".urlencode($username)."&Passwd=%09".urlencode($password)."&service=adsense&ifr=true&rmShown=1&null=Sign+in";
$agent="User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)";
$cookie=dirname(__FILE__)."/cookiefile";
putenv('TZ=US/Pacific'); $randate=mktime(0, 0, 0, date("m"), date("d")-rand(3,26),date("Y"));
$chain=array(
"https://www.google.com/accounts/ServiceloginBoxAuth",
"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=en_US&chtml=loginDoneHtml",
"https://www.google.com/adsense/report/aggregate?sortColumn=0&reverseSort=false&storedReportId=-1&isOldReport=false&product=afc&dateRange.simpleDate=thismonth&dateRange.dateRangeType=custom&dateRange.customDate.start.month="
.date("n",$randate)."&dateRange.customDate.start.day=".date("j",$randate)."&dateRange.customDate.start.year=".date("Y",$randate)."&dateRange.customDate.end.month=".date("n")."&dateRange.customDate.end.day=".date("j")."&dateRange.customDate.end.year=".date("Y")
."&unitPref=page&reportType=property&searchField=&groupByPref=date&csv=true&outputFormat=TSV_EXCEL"
);
$ch = curl_init();
foreach ($chain as $url)
{
curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_TIMEOUT, 35);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
}
curl_close($ch);
// echo "<html>".$result;
Has the login changed again? Because this script won't work for me. I was able to login using the headers I grabbed off of the LiveHTTP Headers plugin, but the CheckCookie request still fails for me. It says my browser doesn't support cookies. I've checked, and the cookie file is there, and open for writing.
Anybody have this working?
<form name="form1" method="post" action="https://www.google.com/adsense/login.do">
<input type="hidden" name="username" value="YOUR_EMAIL">
<input type="hidden" name="password" value="YOUR_PASSWORD">
<input type="hidden" name="destination" value="">
<input type="submit" value="AdSense Login">
</form>
<form name="form1" method="post" action="https://www.google.com/adsense/login.do">
<input type="hidden" name="username" value="YOUR_EMAIL">
<input type="hidden" name="password" value="YOUR_PASSWORD">
<input type="hidden" name="destination" value="">
<input type="submit" value="AdSense Login">
</form>
Might help to add this:
<body>
<script language="javascript">
document.form1.submit();
</script>
</body>