= $int32unit) { $check = ($check - $int32unit * (int) ($check / $int32unit)); //if the check less than -2^31 $check = ($check } $check += ord($str{$i}); } return $check; } //genearate a hash for a url function hashurl($string) { $check1 = strtonum($string, 0×1505, 0×21); $check2 = strtonum($string, 0, 0×1003f); $check1 >>= 2; $check1 = (($check1 >> 4) & 0×3ffffc0 ) | ($check1 & 0×3f); $check1 = (($check1 >> 4) & 0×3ffc00 ) | ($check1 & 0×3ff); $check1 = (($check1 >> 4) & 0×3c000 ) | ($check1 & 0×3fff); $t1 = (((($check1 & 0×3c0) $t2 = (((($check1 & 0xffffc000) return ($t1 | $t2); } //genearate a checksum for the hash string 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; } //return the pagerank checksum hash function getch($url) { return checkhash(hashurl($url)); } //return the pagerank figure function getpr($url) { global $googlehost,$googleua; $pr = 0; // default return $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); } return $pr; } ?>
复制代码