Rumah > pembangunan bahagian belakang > tutorial php > php获取网站的google pr值

php获取网站的google pr值

WBOY
Lepaskan: 2016-07-25 08:57:50
asal
1220 orang telah melayarinya
  1. /**
  2. * php代码取得网站的PR值
  3. * by bbs.it-home.org
  4. */
  5. $googlehost="toolbarqueries.google.com";
  6. $googleua="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5";
  7. echo getpr('http://bbs.it-home.org');
  8. //convert a string to a 32-bit integer
  9. function StrToNum($Str, $Check, $Magic) {
  10. $Int32Unit = 4294967296; // 2^32
  11. $length = strlen($Str);
  12. for ($i = 0; $i $Check *= $Magic;
  13. //If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31),
  14. // the result of converting to integer is undefined
  15. // refer to http://www.php.net/manual/en/language.types.integer.php
  16. if ($Check >= $Int32Unit) {
  17. $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
  18. //if the check less than -2^31
  19. $Check = ($Check }
  20. $Check += ord($Str{$i});
  21. }
  22. return $Check;
  23. }
  24. //genearate a hash for a url
  25. function HashURL($String) {
  26. $Check1 = StrToNum($String, 0×1505, 0×21);
  27. $Check2 = StrToNum($String, 0, 0×1003F);
  28. $Check1 >>= 2;
  29. $Check1 = (($Check1 >> 4) & 0×3FFFFC0 ) | ($Check1 & 0×3F);
  30. $Check1 = (($Check1 >> 4) & 0×3FFC00 ) | ($Check1 & 0×3FF);
  31. $Check1 = (($Check1 >> 4) & 0×3C000 ) | ($Check1 & 0×3FFF);
  32. $T1 = (((($Check1 & 0×3C0) $T2 = (((($Check1 & 0xFFFFC000) return ($T1 | $T2);
  33. }
  34. //genearate a checksum for the hash string
  35. function CheckHash($Hashnum) {
  36. $CheckByte = 0;
  37. $Flag = 0;
  38. $HashStr = sprintf(‘%u’, $Hashnum) ;
  39. $length = strlen($HashStr);
  40. for ($i = $length - 1; $i >= 0; $i –) {
  41. $Re = $HashStr{$i};
  42. if (1 === ($Flag % 2)) {
  43. $Re += $Re;
  44. $Re = (int)($Re / 10) + ($Re % 10);
  45. }
  46. $CheckByte += $Re;
  47. $Flag ++;
  48. }
  49. $CheckByte %= 10;
  50. if (0 !== $CheckByte) {
  51. $CheckByte = 10 - $CheckByte;
  52. if (1 === ($Flag % 2) ) {
  53. if (1 === ($CheckByte % 2)) {
  54. $CheckByte += 9;
  55. }
  56. $CheckByte >>= 1;
  57. }
  58. }
  59. return "7".$CheckByte.$HashStr;
  60. }
  61. //return the pagerank checksum hash
  62. function getch($url) { return CheckHash(HashURL($url)); }
  63. //return the pagerank figure
  64. function getpr($url) {
  65. global $googlehost,$googleua;
  66. $pr = 0; // default return
  67. $ch = getch($url);
  68. $fp = fsockopen($googlehost, 80, $errno, $errstr, 30);
  69. if ($fp) {
  70. $out = "GET /search?client=navclient-auto&ch=$ch&features=Rank&q=info:$url HTTP/1.1\r\n";
  71. //echo “
    $out
    Salin selepas log masuk
    \n”; //debug only
  72. $out .= “User-Agent: $googleua\r\n”;
  73. $out .= “Host: $googlehost\r\n”;
  74. $out .= “Connection: Close\r\n\r\n”;
  75. fwrite($fp, $out);
  76. //$pagerank = substr(fgets($fp, 128), 4); //debug only
  77. //echo $pagerank; //debug only
  78. while (!feof($fp)) {
  79. $data = fgets($fp, 128);
  80. //echo $data;
  81. $pos = strpos($data, “Rank_”);
  82. if($pos === false){} else{
  83. $pr=substr($data, $pos + 9);
  84. $pr=trim($pr);
  85. $pr=str_replace(“\n”,”,$pr);
  86. return $pr;
  87. }
  88. }
  89. //else { echo “$errstr ($errno) \n”; } //debug only
  90. fclose($fp);
  91. }
  92. return $pr;
  93. }
  94. ?>
复制代码


Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan