首頁 > 後端開發 > php教程 > 線上查詢Google PR值的PHP程式碼

線上查詢Google PR值的PHP程式碼

WBOY
發布: 2016-07-25 08:57:44
原創
1172 人瀏覽過
  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
  75. $result[$i] = ord($string{$i});
  76. }
  77. return $result;
  78. }

  79. function ReadPR($link)

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

  82. if (!$fp)

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

  94. do{

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

  102. function GetPR($url)

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

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

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


  117. URL:
复制代码


來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板