Skip to content

Instantly share code, notes, and snippets.

@herrbischoff
Last active August 29, 2015 14:19
Show Gist options
  • Save herrbischoff/6dbaf18f140bfe204bca to your computer and use it in GitHub Desktop.
Save herrbischoff/6dbaf18f140bfe204bca to your computer and use it in GitHub Desktop.
Output Google Pagerank
<?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/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment