当前位置:Gxlcms > PHP教程 > 在线查询GooglePR值的PHP代码

在线查询GooglePR值的PHP代码

时间:2021-07-01 10:21:17 帮助过:34人阅读

  1. /**

  2. * 获取Google PR值
  3. * by bbs.it-home.org
  4. */
  5. define('GOOGLE_MAGIC', 0xE6359A60);
  6. function zeroFill($a, $b)
  7. {
  8. $z = hexdec(80000000);
  9. if ($z & $a)
  10. {
  11. $a = ($a>>1);
  12. $a &= (~$z);
  13. $a |= 0x40000000;
  14. $a = ($a>>($b-1));
  15. }
  16. else
  17. {
  18. $a = ($a>>$b);
  19. }
  20. return $a;
  21. }

  22. function mix($a,$b,$c)

  23. {
  24. $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
  25. $b -= $c; $b -= $a; $b ^= ($a<<8);
  26. $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
  27. $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
  28. $b -= $c; $b -= $a; $b ^= ($a<<16);
  29. $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
  30. $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));
  31. $b -= $c; $b -= $a; $b ^= ($a<<10);
  32. $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
  33. return array($a,$b,$c);
  34. }

  35. function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC)

  36. {
  37. if(is_null($length))
  38. {
  39. $length = sizeof($url);
  40. }
  41. $a = $b = 0x9E3779B9;
  42. $c = $init;
  43. $k = 0;
  44. $len = $length;
  45. while($len >= 12)
  46. {
  47. $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
  48. $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
  49. $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
  50. $mix = mix($a,$b,$c);
  51. $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
  52. $k += 12;
  53. $len -= 12;
  54. }

  55. $c += $length;

  56. switch($len)
  57. {
  58. case 11: $c+=($url[$k+10]<<24);
  59. case 10: $c+=($url[$k+9]<<16);
  60. case 9 : $c+=($url[$k+8]<<8);
  61. case 8 : $b+=($url[$k+7]<<24);
  62. case 7 : $b+=($url[$k+6]<<16);
  63. case 6 : $b+=($url[$k+5]<<8);
  64. case 5 : $b+=($url[$k+4]);
  65. case 4 : $a+=($url[$k+3]<<24);
  66. case 3 : $a+=($url[$k+2]<<16);
  67. case 2 : $a+=($url[$k+1]<<8);
  68. case 1 : $a+=($url[$k+0]);
  69. }
  70. $mix = mix($a,$b,$c);
  71. return $mix[2];
  72. }

  73. function strord($string) {

  74. for($i=0;$i$result[$i] = ord($string{$i});
  75. }
  76. return $result;
  77. }

  78. function ReadPR($link)

  79. {
  80. $fp = fsockopen ("www.google.com", 80, $errno, $errstr, 30);

  81. if (!$fp)

  82. {
  83. echo "$errstr ($errno)\n";
  84. exit(1);
  85. }
  86. else
  87. {
  88. $out = "GET $link HTTP/1.0\r\n";
  89. $out .= "Host: toolbarqueries.google.com\r\n";
  90. $out .= "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114.9-big; Linux 2.6)\r\n";
  91. $out .= "Connection: Close\r\n\r\n";
  92. fwrite($fp, $out);

  93. do{

  94. $line = fgets($fp, 128);
  95. }while ($line !== "\r\n");
  96. $data = fread($fp,8192);
  97. fclose ($fp);
  98. return $data;
  99. }
  100. }

  101. function GetPR($url)

  102. {
  103. $url ='info:'.$url;
  104. $ch = GoogleCH(strord($url));
  105. $data = ReadPR("/search?client=navclient-auto&ch=6$ch&features=Rank&q=$url");
  106. $rankarray = explode (':', $data);
  107. return $rankarray[2];
  108. }

  109. if ( isset($_POST['url']) && $_POST['url'] !== '' )

  110. {
  111. echo 'PageRank: '.GetPR($_POST['url']);
  112. }
  113. ?>
  114. Google PR值查询
  115. Google PR值查询 获取源代码

人气教程排行