= $int32unit) { $check = ($check - $int32unit * (int) ($check / $int32unit)); //if the check less than -2^31 $check = ($check } $check += ord($str{$i}); } return $check;} //将url进行哈希编码function hashurl($string) { $check1 = strtonum($string, 0x1505, 0x21); $check2 = strtonum($string, 0, 0x1003f); $check1 >>= 2; $check1 = (($check1 >> 4) & 0x3ffffc0 ) | ($check1 & 0x3f); $check1 = (($check1 >> 4) & 0x3ffc00 ) | ($check1 & 0x3ff); $check1 = (($check1 >> 4) & 0x3c000 ) | ($check1 & 0x3fff); $t1 = (((($check1 & 0x3c0) $t2 = (((($check1 & 0xffffc000) return ($t1 | $t2);} //为哈希字符串生成校验码function checkhash($hashnum) { $checkbyte = 0; $flag = 0; $hashstr = sprintf('%u', $hashnum) ; $length = strlen($hashstr); for ($i = $length - 1; $i >= 0; $i --) { $re = $hashstr{$i}; if (1 === ($flag % 2)) { $re += $re; $re = (int)($re / 10) + ($re % 10); } $checkbyte += $re; $flag ++; } $checkbyte %= 10; if (0 !== $checkbyte) { $checkbyte = 10 - $checkbyte; if (1 === ($flag % 2) ) { if (1 === ($checkbyte % 2)) { $checkbyte += 9; } $checkbyte >>= 1; } } return '7'.$checkbyte.$hashstr;} //返回pagerank哈希校验码function getch($url) { return checkhash(hashurl($url)); } //返回pr值function getpr($url) { global $googlehost,$googleua; $ch = getch($url); $fp = fsockopen($googlehost, 80, $errno, $errstr, 30); if ($fp) { $out = get /search?client=navclient-auto&ch=$ch&features=rank&q=info:$url http/1.1\r\n; //echo $out
\n; //debug only $out .= user-agent: $googleua\r\n; $out .= host: $googlehost\r\n; $out .= connection: close\r\n\r\n; fwrite($fp, $out); //$pagerank = substr(fgets($fp, 128), 4); //debug only //echo $pagerank; //debug only while (!feof($fp)) { $data = fgets($fp, 128); //echo $data; $pos = strpos($data, rank_); if($pos === false){} else{ $pr=substr($data, $pos + 9); $pr=trim($pr); $pr=str_replace(\n,'',$pr); return $pr; } } //else { echo $errstr ($errno)
\n; } //debug only fclose($fp); }} //生成pagerank图形function pagerank($url,$width=40,$method='style') { if (!preg_match('/^(http:\/\/)?([^\/]+)/i', $url)) { $url='http://'.$url; } $pr=getpr($url); $pagerank=pagerank: $pr/10; //the (old) image method if ($method == 'image') { $prpos=$width*$pr/10; $prneg=$width-$prpos; $html=''; } //the pre-styled method if ($method == 'style') { $prpercent=100*$pr/10; $html='
'; } $out=''.$html.''; return $out;} if ((!isset($_post['url'])) && (!isset($_get['url']))) { echo ''; }if (isset($_request['url'])) { echo pagerank($_request['url']); }?>
复制代码