Guest User

Google PR

a guest
Jan 8th, 2011
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.95 KB | None | 0 0
  1. <?php
  2.  
  3. //www.lampdeveloper.co.uk/
  4. /*
  5.  * convert a string to a 32-bit integer
  6.  */
  7. function StrToNum($Str, $Check, $Magic)
  8. {
  9.     $Int32Unit = 4294967296;  // 2^32
  10.  
  11.     $length = strlen($Str);
  12.     for ($i = 0; $i < $length; $i++) {
  13.         $Check *= $Magic;
  14.         //If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31),
  15.         //  the result of converting to integer is undefined
  16.         //  refer to http://www.php.net/manual/en/language.types.integer.php
  17.         if ($Check >= $Int32Unit) {
  18.             $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
  19.             //if the check less than -2^31
  20.             $Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
  21.         }
  22.         $Check += ord($Str{$i});
  23.     }
  24.     return $Check;
  25. }
  26.  
  27. /*
  28.  * Genearate a hash for a url
  29.  */
  30. function HashURL($String)
  31. {
  32.     $Check1 = StrToNum($String, 0x1505, 0x21);
  33.     $Check2 = StrToNum($String, 0, 0x1003F);
  34.  
  35.     $Check1 >>= 2;
  36.     $Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
  37.     $Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
  38.     $Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);
  39.  
  40.     $T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F );
  41.     $T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );
  42.  
  43.     return ($T1 | $T2);
  44. }
  45.  
  46. /*
  47.  * genearate a checksum for the hash string
  48.  */
  49. function CheckHash($Hashnum)
  50. {
  51.     $CheckByte = 0;
  52.     $Flag = 0;
  53.  
  54.     $HashStr = sprintf('%u', $Hashnum) ;
  55.     $length = strlen($HashStr);
  56.  
  57.     for ($i = $length - 1;  $i >= 0;  $i --) {
  58.         $Re = $HashStr{$i};
  59.         if (1 === ($Flag % 2)) {
  60.             $Re += $Re;
  61.             $Re = (int)($Re / 10) + ($Re % 10);
  62.         }
  63.         $CheckByte += $Re;
  64.         $Flag ++;
  65.     }
  66.  
  67.     $CheckByte %= 10;
  68.     if (0 !== $CheckByte) {
  69.         $CheckByte = 10 - $CheckByte;
  70.         if (1 === ($Flag % 2) ) {
  71.             if (1 === ($CheckByte % 2)) {
  72.                 $CheckByte += 9;
  73.             }
  74.             $CheckByte >>= 1;
  75.         }
  76.     }
  77.  
  78.     return '7'.$CheckByte.$HashStr;
  79. }
  80.  
  81. function getpagerank($url) {
  82.  
  83. $fp = fsockopen("toolbarqueries.google.com", 80, $errno, $errstr, 30);
  84. if (!$fp) {
  85.    echo "$errstr ($errno)<br />\n";
  86. } else {
  87.  $out = "GET /search?client=navclient-auto&ch=".CheckHash(HashURL($url))."&features=Rank&q=info:".$url."&num=100&filter=0 HTTP/1.1\r\n";
  88. $out .= "Host: toolbarqueries.google.com\r\n";
  89. $out .= "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP 5.1)\r\n";
  90. $out .= "Connection: Close\r\n\r\n";
  91.  
  92.    fwrite($fp, $out);
  93.  
  94.    //$pagerank = substr(fgets($fp, 128), 4);
  95.    //echo $pagerank;
  96.    while (!feof($fp)) {
  97.     $data = fgets($fp, 128);
  98.     $pos = strpos($data, "Rank_");
  99.     if($pos === false){} else{
  100.         $pagerank = substr($data, $pos + 9);
  101.         echo $pagerank;
  102.     }
  103.    }
  104.    fclose($fp);
  105.  
  106.    }
  107.  
  108. }
  109.  
  110. echo getpagerank('http://www.coderguru.com');
  111.  
  112.  ?>
Add Comment
Please, Sign In to add comment