does anyone have a google pagerank lookup script that actually works? All the scripts I've used return the following: Forbidden Your client does not have permission to get URL /search?client=navclient-auto&ch=61491030619&features=Rank&q=info%3Ahttp%3A%2F%2Fwww.yahoo.com from this server. (Client IP address: ####) Please see Google's Terms of Service posted at http://www.google.com/terms_of_service.html If you believe that you have received this response in error, please report your problem. However, please make sure to take a look at our Terms of Service (http://www.google.com/terms_of_service.html). In your email, please send us the entire code displayed below. Please also send us any information you may know about how you are performing your Google searches-- for example, "I'm using the Opera browser on Linux to do searches from home. My Internet access is through a dial-up account I have with the FooCorp ISP." or "I'm using the Konqueror browser on Linux to search from my job at myFoo.com. My machine's IP address is 10.20.30.40, but all of myFoo's web traffic goes through some kind of proxy server whose IP address is 10.11.12.13." (If you don't know any information like this, that's OK. But this kind of information can help us track down problems, so please tell us what you can.) We will use all this information to diagnose the problem, and we'll hopefully have you back up and searching with Google again quickly! Please note that although we read all the email we receive, we are not always able to send a personal response to each and every email. So don't despair if you don't hear back from us! Also note that if you do not send us the entire code below, we will not be able to help you. Best wishes, The Google Team /+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/
Those scripts are outdated and Google is blocking them. I also tried on of them and got the same (the only such script on my server). Peace,
But I've tried it on alternate domains and it works. I wonder if it's just blocked from shared hosting servers?
<?php define('GOOGLE_MAGIC', 0xE6359A60); class pageRank{ var $pr; var $pr_val; var $cache_dir = "pr_cache/"; //86400 is 1 day //604800 is 1 week //2419200 is 4 weeks var $cache_time = 604800; function zeroFill($a, $b){ $z = hexdec(80000000); if ($z & $a){ $a = ($a>>1); $a &= (~$z); $a |= 0x40000000; $a = ($a>>($b-1)); }else{ $a = ($a>>$b); } return $a; } function mix($a,$b,$c) { $a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,13)); $b -= $c; $b -= $a; $b ^= ($a<<8); $c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,13)); $a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,12)); $b -= $c; $b -= $a; $b ^= ($a<<16); $c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,5)); $a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,3)); $b -= $c; $b -= $a; $b ^= ($a<<10); $c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,15)); return array($a,$b,$c); } function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) { if(is_null($length)) { $length = sizeof($url); } $a = $b = 0x9E3779B9; $c = $init; $k = 0; $len = $length; while($len >= 12) { $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24)); $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24)); $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24)); $mix = $this->mix($a,$b,$c); $a = $mix[0]; $b = $mix[1]; $c = $mix[2]; $k += 12; $len -= 12; } $c += $length; switch($len){ case 11: $c+=($url[$k+10]<<24); case 10: $c+=($url[$k+9]<<16); case 9 : $c+=($url[$k+8]<<8); /* the first byte of c is reserved for the length */ case 8 : $b+=($url[$k+7]<<24); case 7 : $b+=($url[$k+6]<<16); case 6 : $b+=($url[$k+5]<<8); case 5 : $b+=($url[$k+4]); case 4 : $a+=($url[$k+3]<<24); case 3 : $a+=($url[$k+2]<<16); case 2 : $a+=($url[$k+1]<<8); case 1 : $a+=($url[$k+0]); } $mix = $this->mix($a,$b,$c); /* report the result */ return $mix[2]; } //converts a string into an array of integers containing the numeric value of the char function strord($string) { for($i=0;$i<strlen($string);$i++) { $result[$i] = ord($string{$i}); } return $result; } function query_google($url){ $ch = "6".$this->GoogleCH($this->strord("info:" . $url)); $fp = fsockopen("www.google.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET /search?client=navclient-auto&ch=" . $ch . "&features=Rank&q=info:" . $url . " HTTP/1.1\r\n" ; $out .= "Host: www.google.com\r\n" ; $out .= "Connection: Close\r\n\r\n" ; fwrite($fp, $out); while (!feof($fp)) { $data = fgets($fp, 128); $pos = strpos($data, "Rank_"); if($pos === false){ }else{ $pagerank = substr($data, $pos + 9); $this->pr_val = $pagerank; } } fclose($fp); } } //display pagerank image. Create your own or download images I made for this script. If you make your own make sure to call them pr0.gif, pr1.gif, pr2.gif etc. function pr_image($pagerank){ $pagerank = trim($pagerank); $this->pr = "<img src=\"images/pr".$pagerank.".gif\" alt=\"PageRank " .$pagerank. " out of 10\">" ; } function get_rank($url) { // Include the package require_once('Cache/Lite.php'); // Set a few options $options = array( 'cacheDir' => $this->cache_dir, 'lifeTime' => $this->cache_time ); // Create a Cache_Lite object $Cache_Lite = new Cache_Lite($options); //Check the cache here // Test if thereis a valide cache for this id if ($data = $Cache_Lite->get($url)) { // Cache hit ! $this->pr_val = $data; } else { // No valid cache found (you have to make the page) // Cache miss ! // Put in $data datas to put in cache //Actual code to be run $this->query_google($url); $Cache_Lite->save($this->pr_val); } } //Functions to actually be used by the user //Get a numerical value for the pagerank function Qpr_num($url) { //Query google server $this->get_rank($url); $pr = trim($this->pr_val); //Return the numerical value return $pr; } //Ret the html code to display an image function Qpr_img($url) { //Query google server $this->get_rank($url); //Get image code $this->pr_image($this->pr_val); //Return the image code return $this->pr; } } ?> Code (markup):
Thanks, but that's the code I'm already using. It only returns '1' on my server. I guess it must be a hosting issue
I tried that one too. On localhost it works fine, but on my shared hosting account it gives me that same error. What if we got a unique IP? Could that solve this problem?
only use it on localhost, because its something i still work on. however, the guy who gave it to me has the same code online and it returns the pr there. ant remember the url, but when i was looking for this pr script i had the same problem, and this was the only working solution i found.
I've got a feeling that some IPs get blocked because of abusing this. And there's a good chance that if you're on a shared IP with a thousand other sites, someone is abusing it!