Pages

December 9, 2010

Check Google PageRank dengan PHP


PageRank adalah sebuah algoritma yang telah dipatenkan yang berfungsi menentukan situs web mana yang lebih penting/populer. PageRank merupakan salah satu fitur utama mesin pencari Google.

Sebuah situs akan semakin populer jika semakin banyak situs lain yang meletakkan link yang mengarah ke situsnya, dengan asumsi isi/content situs tersebut lebih berguna dari isi/content situs lain. PageRank dihitung dengan skala 1-10.

Dan untuk melakukan pengecekan PageRank tersebut banyak sekali cara yang digunakan, yaitu salah satunya menggunakan fasilitas yang disediakan oleh website-website yang menyediakan fasilitas tersebut misal (prchecker.info,dll)

Dalam tutorial ini,kita akan membuat fasilitas Check PageRank dengan menggunakan fungsi php. Berikut ini script php nya:
  1. <?php  
  2.     function StrToNum($Str$Check$Magic)  
  3.     {  
  4.         $Int32Unit = 4294967296;  // 2^32  
  5.         $length = strlen($Str);  
  6.   
  7.         for ($i = 0; $i < $length$i++) {  
  8.             $Check *= $Magic;     
  9.             //If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31),   
  10.             //  the result of converting to integer is undefined  
  11.             //  refer to http://www.php.net/manual/en/language.types.integer.php  
  12.   
  13.             if ($Check >= $Int32Unit) {  
  14.                 $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));  
  15.                 //if the check less than -2^31  
  16.                 $Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;  
  17.             }  
  18.   
  19.             $Check += ord($Str{$i});   
  20.         }  
  21.   
  22.         return $Check;  
  23.     }  
  24.   
  25.     function HashURL($String)  
  26.     {  
  27.         $Check1 = StrToNum($String, 0x1505, 0x21);  
  28.         $Check2 = StrToNum($String, 0, 0x1003F);  
  29.   
  30.         $Check1 >>= 2;      
  31.         $Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);  
  32.         $Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);  
  33.         $Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);             
  34.   
  35.         $T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F );  
  36.         $T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );         
  37.   
  38.         return ($T1 | $T2);  
  39.     }  
  40.   
  41.     function CheckHash($Hashnum)  
  42.     {  
  43.         $CheckByte = 0;  
  44.         $Flag = 0;  
  45.   
  46.         $HashStr = sprintf('%u'$Hashnum) ;  
  47.         $length = strlen($HashStr);       
  48.   
  49.         for ($i = $length - 1;  $i >= 0;  $i --) {  
  50.             $Re = $HashStr{$i};  
  51.             if (1 === ($Flag % 2)) {                
  52.                 $Re += $Re;       
  53.                 $Re = (int)($Re / 10) + ($Re % 10);  
  54.             }  
  55.   
  56.             $CheckByte += $Re;  
  57.             $Flag ++;     
  58.         }  
  59.   
  60.         $CheckByte %= 10;  
  61.   
  62.         if (0 !== $CheckByte) {  
  63.             $CheckByte = 10 - $CheckByte;  
  64.             if (1 === ($Flag % 2) ) {  
  65.                 if (1 === ($CheckByte % 2)) {  
  66.                     $CheckByte += 9;  
  67.                 }  
  68.   
  69.                 $CheckByte >>= 1;  
  70.             }  
  71.         }  
  72.   
  73.         return '7'.$CheckByte.$HashStr;  
  74.     }  
  75.   
  76.     function file_get_contents_curl($url) {  
  77.         $ch = curl_init();  
  78.         curl_setopt($ch, CURLOPT_HEADER, 0);  
  79.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
  80.         curl_setopt($ch, CURLOPT_URL, $url);  
  81.         $data = curl_exec($ch);  
  82.   
  83.         curl_close($ch);  
  84.   
  85.         return $data;  
  86.     }  
  87.   
  88.     function getpagerank($url) {  
  89.         $query="http://toolbarqueries.google.com/search?client=navclient-auto&ch=".CheckHash(HashURL($url)). "&features=Rank&q=info:".$url."&num=100&filter=0";  
  90.   
  91.         $data=file_get_contents_curl($query);  
  92.         //print_r($data);  
  93.         $pos = strpos($data"Rank_");  
  94.         if($pos === false){} else{  
  95.             $pagerank = substr($data$pos + 9);  
  96.             return $pagerank;  
  97.         }  
  98.     }  
  99.   
  100.     $url = "http://www.kuliahit.com";  
  101.     echo "Google pagerank = ".getpagerank($url)."<br />";  
  102.   
  103. ?> 

No comments:

Post a Comment