Hey, I have been downloading the various php pagerank checking scripts and not 1 of them has worked when I've uploaded it (they all work on the demos). I am basically after a function that I can pass a url to which finds pagerank. Does anyone have an uptodate script that's working that I can try? Thanks
I think you need to use the Google API at api.google.com but I really don't understand how it works, they have java and CGI examples i think but i have no idea of how they work, because they use some sort of SOAP and things i dunno. Maybe someone can explain how it works, or how to send queries to google using api google? How to SOAP thing works? That might give me a way to design one for you ;O
yep, I tried that one Thats exactly what Im looking for but I get this error: Warning: file(http://www.google.com/search?client=navclient-auto&ch=61054125718&features=Rank&q=info:): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /home/critic/public_html/rankme.php on line 109 PageRank: provided by Google Community.com Seems like the url it's trying to use is forbidden? I just cut-n-paste the code...?
Yep, that's the exact code. I just cut that an pasted it into ultraedit. I didn't change anything. I email the guy who wrote it to see what he thinks about the error.
I just copied and pasted the same code to 'test.php' and replace the last line of code echo 'PageRank: '.getrank($_REQUEST["url"]).'<br /><small>provided by <a href="http://www.googlecommunity.com/" target="_blank">Google Community.com</a></small>'; PHP: with echo 'PageRank: '.getrank('http://www.digitalpoint.com/'); PHP: and it returns: PageRank: 7 so the code is working for me...
Hrm...this is strange. I still get the same error. Would it be possible for you to email me a copy of your code?
This script is working for me. Well, AFAIK it requests PR data from G data center - just like your G toolbar does. So, if you are using this script from behind a proxy server, it might be unable to open stream and fails. Try using it without any proxy and it will definitely work for you, too.
I'm running the script from my web server, theres no proxy I will try to run it from an alternative server and see how I go
I have modified the script to make it more safe (against hacking etc, just incase). And to get rid of the errors you guys are having: <?php // PHP Google PageRank Calculator Script // -------------------------- April 2005 // Contact author: pagerankscript@googlecommunity.com // for updates, visit: // http://www.googlecommunity.com/scripts/google-pagerank.php // provided by www.GoogleCommunity.com // an unofficial community of Google fans // --------------------------------------- // Instructions // Upload pagerank.php to your server // example.com is your website. yahoo.com is the website to get the PR of // The code below displays the PR for $url /* This code is released unto the public domain */ /******* Modified by DesignPlanet.biz *******/ //header("Content-Type: text/plain; charset=utf-8"); define('GOOGLE_MAGIC', 0xE6359A60); //unsigned shift right 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 ^= (zeroFill($c,13)); $b -= $c; $b -= $a; $b ^= ($a<<8); $c -= $a; $c -= $b; $c ^= (zeroFill($b,13)); $a -= $b; $a -= $c; $a ^= (zeroFill($c,12)); $b -= $c; $b -= $a; $b ^= ($a<<16); $c -= $a; $c -= $b; $c ^= (zeroFill($b,5)); $a -= $b; $a -= $c; $a ^= (zeroFill($c,3)); $b -= $c; $b -= $a; $b ^= ($a<<10); $c -= $a; $c -= $b; $c ^= (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 = mix($a,$b,$c); $a = $mix[0]; $b = $mix[1]; $c = $mix[2]; $k += 12; $len -= 12; } $c += $length; switch($len) /* all the case statements fall through */ { 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]); /* case 0: nothing left to add */ } $mix = 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 getrank($url) { $url = 'info:'.$url; $ch = GoogleCH(strord($url)); $file = "http://www.google.com/search?client=navclient-auto&ch=6$ch&features=Rank&q=$url"; $data = file($file); $rankarray = explode (':', $data[2]); $rank = $rankarray[2]; return $rank; } $url = addslashes(trim($_GET['url'])); if((!$url) || (empty($url))){ echo "<b>Error</b><br />You have not entered a URL to Search!"; exit(); } if((eregi('%0d', $url)) || (eregi('%0a', $url))){ echo "<b>Error</b><br />Invalid Characters!"; } echo '<b>'.$url.'</b> PageRank: <b>'.getrank($url).'</b><br />'; ?> PHP:
Same error I'm thinking this has something to do with google not allowing me to access their datacenter from my server...hence the forbidden error.
I just tried this exact script on a free php hosting site, and same error. Does anyone have (or know of) a completely different script I can try?
Works for me too, I've tried it at least on 2 servers. If one thing is a little off in the url you send google, you'll get the forbidden error. Can't be done with API.
i hope you are doing something like http://example.com/PRscript.php?url=http://www.designplanet.biz or in that syntax, or you might get an error. But no you Should NOT get an error, you MUST be doing something wrong. Can you copy and paste the exact code, (without the PHP tags) into here... Maybe you copied it wrong or added something accidently.
I copied your code from a few posts ago. Here it is: define('GOOGLE_MAGIC', 0xE6359A60); //unsigned shift right 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 ^= (zeroFill($c,13)); $b -= $c; $b -= $a; $b ^= ($a<<8); $c -= $a; $c -= $b; $c ^= (zeroFill($b,13)); $a -= $b; $a -= $c; $a ^= (zeroFill($c,12)); $b -= $c; $b -= $a; $b ^= ($a<<16); $c -= $a; $c -= $b; $c ^= (zeroFill($b,5)); $a -= $b; $a -= $c; $a ^= (zeroFill($c,3)); $b -= $c; $b -= $a; $b ^= ($a<<10); $c -= $a; $c -= $b; $c ^= (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 = mix($a,$b,$c); $a = $mix[0]; $b = $mix[1]; $c = $mix[2]; $k += 12; $len -= 12; } $c += $length; switch($len) /* all the case statements fall through */ { 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]); /* case 0: nothing left to add */ } $mix = 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 getrank($url) { $url = 'info:'.$url; $ch = GoogleCH(strord($url)); $file = "http://www.google.com/search?client=navclient-auto&ch=6$ch&features=Rank&q=$url"; $data = file($file); $rankarray = explode (':', $data[2]); $rank = $rankarray[2]; return $rank; } $url = addslashes(trim($_GET['url'])); if((!$url) || (empty($url))){ echo "<b>Error</b><br />You have not entered a URL to Search!"; exit(); } if((eregi('%0d', $url)) || (eregi('%0a', $url))){ echo "<b>Error</b><br />Invalid Characters!"; } echo '<b>'.$url.'</b> PageRank: <b>'.getrank($url).'</b><br />';