Google | PHP | Publicidad
Hacer login a Google Adsense con PHP
Un ejemplo para conectarnos a Google Adsense usando cURL, usa a parte de cookies, el USER AGENT y las cabeceras REFERRER HTTP headers.
<?php
// Descomentar solo para admitir cierta IP
// if($_SERVER['REMOTE_ADDR'] !== '1.1.1.1') die();
$usuario=urlencode('myemail@gmail.com');
$password="micontraseña";
$gacookie="./.gacookie";
$postdata="Email=$usuario&Passwd=$password&GA3T=5AS_gBsvDHI&nui=15&fpui=3"
."&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);
$result = curl_exec ($ch);
curl_close($ch);
echo $result;
unlink($gacookie);
exit;
?>