Important: This script has been updated as of May 2012, so the script runs on 64bit operating systems.
Recently, I’ve been searching for a PHP script that was able to retrieve the pagerank of a specific web page, since Google doesn’t provide an API for it. I found many options, although none of them worked since Google has changed their pagerank hash, so therefore, I have decided to dig through the Google Toolbar source code, and find out on my own.
<?php
function genhash ($url) {
$hash = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer.";
$c = 16909125;
$length = strlen($url);
$hashpieces = str_split($hash);
$urlpieces = str_split($url);
for ($d = 0; $d < $length; $d++) {
$c = $c ^ (ord($hashpieces[$d]) ^ ord($urlpieces[$d]));
$c = (($c >> 23) & 0x1ff) | $c << 9;
}
$c = -(~($c & 4294967295) + 1);
return '8' . dechex($c);
}
function pagerank($url) {
$googleurl = 'http://toolbarqueries.google.com/tbr?client=navclient-auto&ch=' . genhash($url) . '&features=Rank&q=info:' . urlencode($url);
if(function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $googleurl);
$out = curl_exec($ch);
curl_close($ch);
} else {
$out = file_get_contents($googleurl);
}
if(strlen($out) > 0) {
return trim(substr(strrchr($out, ':'), 1));
} else {
return -1;
}
}
echo pagerank('http://www.fusionswift.com/');
?>
You may have been brought here from the October 2011 version of the script. While the original date on this post is from older back, this is the “more” working version. The October 2011 version works, though only on 32 bit operating systems.
Btw., is there any requests/day/ip limitation on your API?
How about Google?
Unfortunately it does not work for links longer then 88 chars.. any updates on this?
cheers, and thank you very much for your work.
I think there is some kind of limitation. I tried more than 200 query a day and google stop answering my requests.
sorry. your API is no longer work.
but, still, thank you for the API.
Hi,
It looks like it does not work any more… R U aware of any change by Google?
Your API doesn’t work. returns digits…
Hello,
I am experimenting with some scripts I have found online in order to get the Google’s PageRank of a specified page.
All the scripts, including yours, seem not to work.
Whatever URL you try, the pagerank is (blank) and if I try the api:
http://api.fusionswift.com/pagerank/?url=http://fusionswift.com/
it will show the same numbers regardless the URL specified. I guess it’s not working.
It seems that in 2007 the PageRank check was very simple to perform, by means of PHP4 and some SOAP script.
There was a Google Api which could be used – nowadays at Google they seem to have wiped away this API. There are many APIs to interact with most Google services, but not Web Search: I can only find a Ajax API (working!) but it not yelds any PageRank data… Just good for plain searches.
Anybody can shed some light on this?
Our API is in fact having some issues at the moment. However, our pagerank() function should still be working.
we used the above code but the page rank is blank..what is the problem? what we have to do further?
is there any limitation for daily pagerank check?
As I remember google is selling pagerank check.
But the first 1000 is free.
Anybody knows something about this?
Thanks in advance
I’m not sure what Google’s policy is. I don’t think Google officially sells pagerank check. I haven’t seen anything like that around.
This script is not working for me, not sure what’s the issue. couldl someone pl. help me.
Are you under a 64 bit operating system? Unfortunately this only works under 32 bit at the moment.