演示页: http://gi.2288.org:88/t/pro/pagerank.php
<?PHP
/****************************************************************\
* 绿色学院 - Green Institute
* author Emerald<[email protected]>
* homepage http://gi.2288.org:88/
* 时间 2005-01-24
\****************************************************************/
echo"<title>绿色学院 - Green Institute - 不听人间乐 - 想得到 - 做得到</title>";
error_reporting(E_ALL & ~E_NOTICE);
$header = <<<WAPH
WAPH;
$footer = <<<WAPF
WAPF;
$prt = new getPR($_REQUEST['url']);
$pagerank = $prt->getrank();
echo $header;
echo "PageRank = $pagerank";
echo $footer;
echo"<form action=pagerank2.php?url=".url."method=post>";
echo "请在此处输入域名:<input name=".url.">";
echo "</form>";
/**
* 取得google PageRank 数值
**/
class getPR
{
var $google_magic = 0xE6359A60;
var $url = '';
function getPR($url = "")
{
if ("" != $url) $this->url = $url;
}
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 = "")
{
if ("" == $init) $init = $this->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);
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 = $this->mix($a,$b,$c);
return $mix[2];
}
function strord($string)
{
for($i=0; $i<strlen($string); $i++) {
$result[$i] = ord($string{$i});
}
return $result;
}
function getrank()
{
$this->url = 'info:' . $this->url;
$file = "http://www.google.com/search?client=navclient-auto&ch=6".$this->GoogleCH($this->strord($this->url))."&features=Rank&q=".$this->url;
$data = $this->naps_get_html($file);
if ($data) {
$rankarray = explode (':', $data);
$rank = $rankarray[2];
return $rank;
} else {
return '取得远程文件错误!';
}
}
function naps_get_html($file)
{
$fp = @fopen($file, 'rb');
if ($fp) {
do {
$urldata = @fread($fp, 8192);
if (strlen($urldata) == 0) break;
$result .= $urldata;
} while(true);
return $result;
} else {
return false;
}
}
}
?>
本文地址:http://com.8s8s.com/it/it23453.htm