<?PHP
error_reporting(E_ALL & ~E_NOTICE);
$header = <<<WAPH
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>取得PageRank</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
body,td,tr,th {
font-size: 9pt;
}
-->
</style></head>
<body>
WAPH;
$footer = <<<WAPF
</body>
</html>
WAPF;
$prt = new getPR($_REQUEST['url']);
$pagerank = $prt->getrank();
echo $header;
echo "你网站的PageRank = $pagerank";
echo $footer;
/**
* 取得google PageRank 数值
**/
class getPR
{
var $google_magic = 0xE6359A60;
var $url = 'www.n139.com';
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;
}
}
}
?>
看了这些代码..有点迷惑不解..为何在代码中增加数组及8位二进制数呢??
这些是什么意思..有点茫然..
本文地址:http://com.8s8s.com/it/it22317.htm