Php obtains the googlepr value of the website.

Source: Internet
Author: User
Php obtains the googlepr value of the website.

  1. /**
  2. * The php code gets the prvalue of the website.
  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 <$ length; $ I ++ ){
  13. $ Check * = $ Magic;
  14. // If the float is beyond the boundaries of integer (usually +/-2.15e + 9 = 2 ^ 31 ),
  15. // The result of converting to integer is undefined
  16. // Refer to http://www.php.net/manual/en/language.types.integer.php
  17. If ($ Check >=$ Int32Unit ){
  18. $ Check = ($ Check-$ Int32Unit * (int) ($ Check/$ Int32Unit ));
  19. // If the check less than-2 ^ 31
  20. $ Check = ($ Check <-2147483648 )? ($ Check + $ Int32Unit): $ Check;
  21. }
  22. $ Check + = ord ($ Str {$ I });
  23. }
  24. Return $ Check;
  25. }
  26. // Genearate a hash for a url
  27. Function HashURL ($ String ){
  28. $ Check1 = StrToNum ($ String, 0 × 1505, 0 × 21 );
  29. $ Check2 = StrToNum ($ String, 0, 0 × 1003F );
  30. $ Check1 >>=2;
  31. $ Check1 = ($ Check1> 4) & 0 × 3FFFFC0) | ($ Check1 & 0 × 3F );
  32. $ Check1 = ($ Check1> 4) & 0 × 3FFC00) | ($ Check1 & 0 × 3FF );
  33. $ Check1 = ($ Check1> 4) & 0 × 3C000) | ($ Check1 & 0 × 3FFF );
  34. $ T1 = ($ Check1 & 0 × 3C0) <4) | ($ Check1 & 0 × 3C) <2) | ($ Check2 & 0xF0F );
  35. $ T2 = ($ Check1 & 0xFFFFC000) <4) | ($ Check1 & 0 × 3C00) <0xA) | ($ Check2 & 0xF0F0000 );
  36. Return ($ T1 | $ T2 );
  37. }
  38. // Genearate a checksum for the hash string
  39. Function CheckHash ($ Hashnum ){
  40. $ CheckByte = 0;
  41. $ Flag = 0;
  42. $ HashStr = sprintf ('% u', $ Hashnum );
  43. $ Length = strlen ($ HashStr );
  44. For ($ I = $ length-1; $ I> = 0; $ I -){
  45. $ Re = $ HashStr {$ I };
  46. If (1 ===( $ Flag % 2 )){
  47. $ Re + = $ Re;
  48. $ Re = (int) ($ Re/10) + ($ Re % 10 );
  49. }
  50. $ CheckByte + = $ Re;
  51. $ Flag ++;
  52. }
  53. $ CheckByte % = 10;
  54. If (0! ==$ CheckByte ){
  55. $ CheckByte = 10-$ CheckByte;
  56. If (1 ===( $ Flag % 2 )){
  57. If (1 ===( $ CheckByte % 2 )){
  58. $ CheckByte + = 9;
  59. }
  60. $ CheckByte >>=1;
  61. }
  62. }
  63. Return "7". $ CheckByte. $ HashStr;
  64. }
  65. // Return the pagerank checksum hash
  66. Function getch ($ url) {return CheckHash (HashURL ($ url ));}
  67. // Return the pagerank figure
  68. Function getpr ($ url ){
  69. Global $ googlehost, $ googleua;
  70. $ Pr = 0; // default return
  71. $ Ch = getch ($ url );
  72. $ Fp = fsockopen ($ googlehost, 80, $ errno, $ errstr, 30 );
  73. If ($ fp ){
  74. $ Out = "GET/search? Client = navclient-auto & ch = $ ch & features = Rank & q = info: $ url HTTP/1.1 \ r \ n ";
  75. // Echo"
    $out
    \ N "; // debug only
  76. $ Out. = "User-Agent: $ googleua \ r \ n ";
  77. $ Out. = "Host: $ googlehost \ r \ n ";
  78. $ Out. = "Connection: Close \ r \ n ";
  79. Fwrite ($ fp, $ out );
  80. // $ Pagerank = substr (fgets ($ fp, 128), 4); // debug only
  81. // Echo $ pagerank; // debug only
  82. While (! Feof ($ fp )){
  83. $ Data = fgets ($ fp, 128 );
  84. // Echo $ data;
  85. $ Pos = strpos ($ data, "Rank _");
  86. If ($ pos = false) {} else {
  87. $ Pr = substr ($ data, $ pos + 9 );
  88. $ Pr = trim ($ pr );
  89. $ Pr = str_replace ("\ n", ", $ pr );
  90. Return $ pr;
  91. }
  92. }
  93. // Else {echo "$ errstr ($ errno) \ n";} // debug only
  94. Fclose ($ fp );
  95. }
  96. Return $ pr;
  97. }
  98. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.