GooglePR query interface checksum new algorithm _ php instance

Source: Internet
Author: User
Some days ago, an article N long ago suddenly became a hot topic for reading, after checking, I found that my page using that code for pr query could not normally get the URL PageRank value. some days ago, an article about N long ago suddenly became a hot topic to be read, after checking, I found that the Page that I used that code for pr query cannot get the Page Rank value of the URL normally.

Replaced by a large segment of Google terms_of_service error messages such as "In your email, please send us the entire code displayed below. It seems that the original interface has expired.

However, the extension SearchStatus that I installed in the Firefox toolbar can still parse the prvalue of each page visited, find the plug-in package of SearchStatus to unbind the source code, and use a different verification code generation algorithm, after the original checksum is generated, another calculation is required. after the two computations, the correct ch parameter is obtained.

As a result, the new PHP version's Google PageRank query interface method came out after the ready-made js code transformation. After the local test, the terms_of_service error message is displayed after the user wants to upload the data to the server. After calculating the checksum step by step, it is found that the numbers on the local server and the server are different after several right shifts. This reminds us that the server is a 64-bit server. after the 32-bit system is displaced, the dropped bit will survive well. A trunkbitForce32bit method is added to shield the values after all arithmetic operations at a high level. This solves the extra bit problem in a 64-bit system. The result shows that the 32-bit Linux environment is incompatible because PHP automatically tries to convert int to float when the arithmetic processing overflows. When a negative overflow occurs, this operation correctly retains the precision in Windows, but there is a problem in Linux.

The following code:

$ A =-4294967295;
Echo dechex ($ )."
\ N ";
If ($ a <0) $ a + = 4294967296;
Echo dechex ($ )."
\ N ";

In Windows, the first echo can correctly output the 32-bit complement code of this negative number, while in 32-bit Linux, the output is the maximum number 0x80000000 that the int type can represent. Only by adding a large integer out of the integer range to the large negative number of the overflow in a clever way can the system restore the 32-bit low.

Using these unconventional methods, we finally developed the PHP script implementation (including the complete code) for this new version of the Google prvalue query interface compatible with Linux32, Linux64, and Windows ).

Google itself provides an interface for querying the PageRank value of a specified url. with this interface, you can easily write scripts to implement this function on the page, you do not need to rely on google toolbar for query. This article provides a pr query interface implemented using PHP. At the same time, the checksum cannot be generated normally in most versions of Linux and 64-bit operating systems.

Easy to use, as long as you need

Include_once ("./pr. inc. php ");
Echo getPR ($ urlToQuery );

The PageRank value of the specified url is displayed. It is not difficult to simulate the graphic pr display on the Google Toolbar based on this value. In fact, the implementation principle is quite simple, that is, passing specific query parameters to Google's search engine and then capturing the returned page content.

For the demo page, see Google PageRank Query

Source of the code material in this article: #; implementation of the NewGCH method refer to the code implementation of the Firefox toolbar extension SearchStatus.

There is also an open-source pr status query project on the Internet: #, you can directly capture the complete source code from cvs (cvs user password guest ):

Cvs-d: pserver: login
Cvs-d: pserver: co pagerankstatus

A website dedicated to the pr display interface :#


The source file of pr. inc. php is as follows (Updated-- Google modified the calculation algorithm of checksum. we need to set a NewGCH method after the original GCH method to get the correct checksum. for the compatibility problem of php int overflow and 64-bit machines, seeThe following source code changes ):

 >1); $a &= (~$z); $a |= hexdec('4'.implode('',array_fill(0,PHP_INT_SIZE*2-1,'0'))); $a = ($a>>($b-1)); } else{ $a = ($a>>$b); } return $a; } // discard bits beyonds 32 bit. function trunkbitForce32bit($n){ if(PHP_INT_SIZE <= 4){ settype($n,'float'); if ( $n < 0 ) $n += 4294967296; return $n; } else{ $clearbit = ''; for($i=0;$i
  = 12 ){ $a += ($url[$k+0] +trunkbitForce32bit($url[$k+1]<<8) +trunkbitForce32bit($url[$k+2]<<16) +trunkbitForce32bit($url[$k+3]<<24)); $b += ($url[$k+4] +trunkbitForce32bit($url[$k+5]<<8) +trunkbitForce32bit($url[$k+6]<<16) +trunkbitForce32bit($url[$k+7]<<24)); $c += ($url[$k+8] +trunkbitForce32bit($url[$k+9]<<8) +trunkbitForce32bit($url[$k+10]<<16) +trunkbitForce32bit($url[$k+11]<<24)); $mixo = mix($a,$b,$c); $a = $mixo[0]; $b = $mixo[1]; $c = $mixo[2]; $k += 12; $len -= 12; } $c += $length; switch( $len ) { case 11: $c += trunkbitForce32bit($url[$k+10]<<24); case 10: $c+=trunkbitForce32bit($url[$k+9]<<16); case 9 : $c+=trunkbitForce32bit($url[$k+8]<<8); case 8 : $b+=trunkbitForce32bit($url[$k+7]<<24); case 7 : $b+=trunkbitForce32bit($url[$k+6]<<16); case 6 : $b+=trunkbitForce32bit($url[$k+5]<<8); case 5 : $b+=trunkbitForce32bit($url[$k+4]); case 4 : $a+=trunkbitForce32bit($url[$k+3]<<24); case 3 : $a+=trunkbitForce32bit($url[$k+2]<<16); case 2 : $a+=trunkbitForce32bit($url[$k+1]<<8); case 1 : $a+=trunkbitForce32bit($url[$k+0]); } $mixo = mix( $a, $b, $c ); $mixo[2] = trunkbitForce32bit($mixo[2]); if( $mixo[2] < 0 ){ return ( hexdec('1'. implode('', array_fill(0,PHP_INT_SIZE*2,'0'))) + $mixo[2] ); } else{ return $mixo[2]; } } // converts a string into an array of integers // containing the numeric value of the char function strord($string){ for($i=0;$i
Related Article

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: 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.