Wednesday, February 18, 2009

Make Google PageRank

Google search engine will give the value or PageRank for any URL with the algorithm too. To do this for Google PageRank? Certainly, according to the name to determine the ranking of a URL in its database engine. The higher the ranking of a URL will be located at the top in the search results on Google.

To create a Google PageRank of the URL you're not hard, because Google provides the modules to create the PageRank of a URL. In this occasion I will submit two PHP scripts that you can plug in your URL to determine the PageRank of a URL.

First is the script to call the Google PageRank module. This simple script can be developed to become more interactive, where visitors can enter your website URL PageRank of interest.

Create a file pr.php as below with the editor that you use often.




  1. // pagerank.php adalah nama file yang berisi modul pagerank google

  2. include('pagerank.php');

  3. $pr = getPageRank('http://infokomtek.com');

  4. echo 'Page rank dari infokomtek.com adalah '.$pr;

  5. ?>

Then, create a file pagerank.php as below with the save in the same directory with the files that have been pr.php we make earlier.


  1. php

  2. define('GOOGLE_MAGIC', 0xE6359A60);

  3. function _zeroFill($a, $b){
  4. $z = hexdec(80000000);
  5. if ($z & $a){
  6. $a = ($a>>1);
  7. $a &= (~$z);
  8. $a |= 0x40000000;
  9. $a = ($a>>($b-1));
  10. }else
  11. $a = ($a>>$b);
  12. return $a;
  13. }

  14. function _mix($a,$b,$c){
  15. $a -= $b; $a -= $c; $a ^= (_zeroFill($c,13));
  16. $b -= $c; $b -= $a; $b ^= ($a<<8);>
  17. $c -= $a; $c -= $b; $c ^= (_zeroFill($b,13));
  18. $a -= $b; $a -= $c; $a ^= (_zeroFill($c,12));
  19. $b -= $c; $b -= $a; $b ^= ($a<<16);>
  20. $c -= $a; $c -= $b; $c ^= (_zeroFill($b,5));
  21. $a -= $b; $a -= $c; $a ^= (_zeroFill($c,3));
  22. $b -= $c; $b -= $a; $b ^= ($a<<10);>
  23. $c -= $a; $c -= $b; $c ^= (_zeroFill($b,15));
  24. return array($a,$b,$c);
  25. }

  26. function _GoogleCH($url, $length=null, $init=GOOGLE_MAGIC){
  27. if(is_null($length))
  28. $length = sizeof($url);
  29. $a = $b = 0x9E3779B9;
  30. $c = $init;
  31. $k = 0;
  32. $len = $length;
  33. while($len >= 12){
  34. $a += ($url[$k + 0] + ($url[$k + 1] << "http://infokomtek.com/wp-includes/images/smilies/icon_cool.gif" alt="8)" class="wp-smiley"> + ($url[$k + 2] <<>$url[$k + 3] <<>
  35. $b += ($url[$k + 4] + ($url[$k + 5] << "http://infokomtek.com/wp-includes/images/smilies/icon_cool.gif" alt="8)" class="wp-smiley"> + ($url[$k + 6] <<>$url[$k + 7] <<>
  36. $c += ($url[$k + 8] + ($url[$k + 9] << "http://infokomtek.com/wp-includes/images/smilies/icon_cool.gif" alt="8)" class="wp-smiley"> + ($url[$k + 10] <<>$url[$k + 11] <<>
  37. $_mix = _mix($a,$b,$c);
  38. $a = $_mix[0]; $b = $_mix[1]; $c = $_mix[2];
  39. $k += 12;
  40. $len -= 12;
  41. }
  42. $c += $length;
  43. switch($len){
  44. case 11: $c += ($url[$k + 10] <<>
  45. case 10: $c += ($url[$k + 9] <<>
  46. case 9 : $c += ($url[$k + 8] <<>
  47. case 8 : $b += ($url[$k + 7] <<>
  48. case 7 : $b += ($url[$k + 6] <<>
  49. case 6 : $b += ($url[$k + 5] <<>
  50. case 5 : $b += ($url[$k + 4]);
  51. case 4 : $a += ($url[$k + 3] <<>
  52. case 3 : $a += ($url[$k + 2] <<>
  53. case 2 : $a += ($url[$k + 1] <<>
  54. case 1 : $a += ($url[$k + 0]);
  55. }
  56. $_mix = _mix($a,$b,$c);
  57. return $_mix[2];
  58. }

  59. function _strord($string){
  60. for($i = 0;$i < strlen($string);$i++)
  61. $result[$i] = ord($string{$i});
  62. return $result;
  63. }

  64. function getPageRank($url){
  65. $pagerank = -1;
  66. $ch = "6"._GoogleCH(_strord("info:" . $url));
  67. $fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
  68. if($fp){
  69. $out = "GET /search?client=navclient-auto&amp;ch=" . $ch . "&amp;features=Rank&amp;q=info:" . $url . " HTTP/1.1\r\n";
  70. $out .= "Host: www.google.com\r\n";
  71. $out .= "Connection: Close\r\n\r\n";
  72. fwrite($fp, $out);
  73. while (!feof($fp)){
  74. $data = fgets($fp, 128);
  75. $pos = strpos($data, "Rank_");
  76. if($pos === false){
  77. }else
  78. $pagerank = substr($data, $pos + 9);
  79. }
  80. fclose($fp);
  81. }
  82. return $pagerank;
  83. }

  84. ?>

  1. regular_rules is that we run the script before running the script above. This script contains the policy of iptables before we have removed with the command iptables-F. Certainly, if you do not have a policy in your iptables, regular_rules line is not needed.

No comments:

Post a Comment