coockieFile = tempnam($this->tmpPath, 'cookie'); $this->curl = curl_init(); curl_setopt($this->curl, CURLOPT_HEADER, false); curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($this->curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7"); curl_setopt($this->curl, CURLOPT_COOKIEFILE, $cookieFile); curl_setopt($this->curl, CURLOPT_COOKIEJAR, $cookieFile); register_shutdown_function(array(&$this, '__destructor')); } /** * AdSense::__destructor() * AdSense class destructor */ function __destructor(){ @curl_close($this->curl); @unlink($this->coockieFile); } /** * AdSense::connect() * Connects to AdSense account using supplied credentials * Returns true on unsuccessful connection, false otherwise * * @param string $username AdSense username * @param string $password AdSense password * @return boolean */ function connect($username, $password){ // phase 1 curl_setopt($this->curl, CURLOPT_URL, "https://www.google.com/accounts/ServiceLoginAuth?service=adsense&hl=en-US<mpl=login&ifr= true&passive=true&rm=hide&nui=3&alwf=true&continue=https%3A%2F%2Fwww.google.com%2Fadsense% 2Fgaiaauth&followup=https%3A%2F%2Fwww.google.com%2Fadsense%2Fgaiaauth"); preg_match_all('', curl_exec($this->curl), $out); $params = array(); foreach($out[1] as $key=>$name) { $params[] = $name . '=' . urlencode($out[2][$key]); } $params[] = 'Email=' . urlencode($username); $params[] = 'Passwd=' . urlencode($password); $params[] = 'null=' . urlencode('Sign in'); // phase 2 curl_setopt($this->curl, CURLOPT_POST, true); curl_setopt($this->curl, CURLOPT_URL, "https://www.google.com/accounts/ServiceLoginAuth"); curl_setopt($this->curl, CURLOPT_POSTFIELDS, join('&', $params)); preg_match("/.*curl), $matches); // phase 3 curl_setopt($this->curl, CURLOPT_POST, false); curl_setopt($this->curl, CURLOPT_URL, $matches[1]); // did we login ? if (eregi("Log out", curl_exec($this->curl))) { return true; } else { return false; }; } /** * AdSense::parse() * Parses AdSense page and gets all stats * Returns associative array with collected data * * @param string $content AdSense page content * @return array */ function parse($content){ preg_match_all('/