} // Get the Google Pagerank function getPagerank($url) { $query = "http://toolbarqueries.google.com/search?client=navclient-auto&ch=" . $this->CheckHash($this->HashURL($url)) . "&features=Rank&q=info:" . $url . "&num=100&filter=0"; $data = $this->file_get_contents_curl($query); $pos = strpos($data, "Rank_"); if ($pos !== false) { $pagerank = substr($data, $pos + 9); return trim($pagerank); } } // Use curl the get the file contents function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Set curl to return the data instead of printing it to the browser. curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } } ?> <?php $gpr = new GooglePR(); echo $gpr->getPagerank('google.com'); echo "hello";
<?php $obj = new GooglePR(); $pr = $obj->getPR('http://www.overclockers.com.au'); echo $pr; class GooglePR { public $googleDomains = array("toolbarqueries.google.com", "www.google.com"); public $userAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204"; function getPR($url) { $result = array(); $contents = ""; if ($url . "" != "" && $url . "" != "http://") { $this->cacheDir .= substr($this->cacheDir, -1) != "/" ? "/" : ""; $url_ = substr(strtolower($url), 0, 7) != "http://" ? "http://" . $url : $url; $host = $this->googleDomains[mt_rand(0, count($this->googleDomains) - 1)]; $url = sprintf("http://%s/search?client=navclient-auto&ch=%s&features=Rank&q=%s", $host, $this->CheckHash($this->HashURL($url_)), urlencode("info:" . $url_)); $context_options = array(); $context_options['http']['user_agent'] = $this->userAgent; $context = stream_context_create($context_options); $contents = trim(file_get_contents($url, FALSE, $context)); $result['Response'] = $contents; // Rank_1:1:0 = 0 // Rank_1:1:5 = 5 // Rank_1:1:9 = 9 // Rank_1:2:10 = 10 etc $p = explode(":", $contents); if (isset($p[2])) { $result['Pagerank'] = $p[2]; }
function getPageRank($url) { $pagerank = -1; $gpr = new GooglePR(); $gpr->useCache = false; $pagerank = $gpr->GetPR($url); return intval($pagerank); }
echo 'Start fetch Web Rank: ' . date("Y-m-d H:i:s") . '<br>'; foreach ($accounts as $account) { echo 'Get stat for: ' . $account['url'] . ' - ' . date("Y-m-d H:i:s") . '<br>'; $result = array(); if ($fetchAlexa) { //alexa rank //http://xml.alexa.com/data?cli=10&url=[siteurl] $ch = getCURLResource(); curl_setopt($ch, CURLOPT_URL, "http://xml.alexa.com/data?cli=10&url=" . $account['url']); $buf2 = curl_exec($ch); curl_close($ch); $xml = xml2ary($buf2); $alexarank = $xml['ALEXA']['_c']['SD']['_c']['POPULARITY']['_a']['TEXT']; echo 'Alexa rank: ' . $alexarank . '<br>'; } $result['alexarank'] = $alexarank; if ($fetchGooglePR) { $gpr = new GooglePR(); $gpr->userAgent = $_SERVER["HTTP_USER_AGENT"]; $gpr->cacheDir = dirname(__FILE__) . "/prcache"; $gpr->maxCacheAge = 86400; $gpr->useCache = false; $googlepr = $gpr->GetPR($account['url']); echo 'Google pagerank: ' . $googlepr . '<br>'; } $result['grank'] = $googlepr; if ($saveToDB) { saveRankStat($account, $result); } } echo 'End fetch Web Rank: ' . date("Y-m-d H:i:s") . '<br>';