Php obtains the googlepr value of the website.
- /**
- * The php code gets the prvalue of the website.
- * By bbs.it-home.org
- */
- $ Googlehost = "toolbarqueries.google.com ";
- $ Googleua = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: 1.8.0.6) Gecko/20060728 Firefox/1.5 ";
- Echo getpr ('http: // bbs.it-home.org ');
- // Convert a string to a 32-bit integer
- Function StrToNum ($ Str, $ Check, $ Magic ){
- $ Int32Unit = 4294967296; // 2 ^ 32
- $ Length = strlen ($ Str );
- For ($ I = 0; $ I <$ length; $ I ++ ){
- $ Check * = $ Magic;
- // If the float is beyond the boundaries of integer (usually +/-2.15e + 9 = 2 ^ 31 ),
- // The result of converting to integer is undefined
- // Refer to http://www.php.net/manual/en/language.types.integer.php
- If ($ Check >=$ Int32Unit ){
- $ Check = ($ Check-$ Int32Unit * (int) ($ Check/$ Int32Unit ));
- // If the check less than-2 ^ 31
- $ Check = ($ Check <-2147483648 )? ($ Check + $ Int32Unit): $ Check;
- }
- $ Check + = ord ($ Str {$ I });
- }
- Return $ Check;
- }
- // Genearate a hash for a url
- Function HashURL ($ String ){
- $ Check1 = StrToNum ($ String, 0 × 1505, 0 × 21 );
- $ Check2 = StrToNum ($ String, 0, 0 × 1003F );
- $ Check1 >>=2;
- $ Check1 = ($ Check1> 4) & 0 × 3FFFFC0) | ($ Check1 & 0 × 3F );
- $ Check1 = ($ Check1> 4) & 0 × 3FFC00) | ($ Check1 & 0 × 3FF );
- $ Check1 = ($ Check1> 4) & 0 × 3C000) | ($ Check1 & 0 × 3FFF );
- $ T1 = ($ Check1 & 0 × 3C0) <4) | ($ Check1 & 0 × 3C) <2) | ($ Check2 & 0xF0F );
- $ T2 = ($ Check1 & 0xFFFFC000) <4) | ($ Check1 & 0 × 3C00) <0xA) | ($ Check2 & 0xF0F0000 );
- Return ($ T1 | $ T2 );
- }
- // Genearate a checksum for the hash string
- Function CheckHash ($ Hashnum ){
- $ CheckByte = 0;
- $ Flag = 0;
- $ HashStr = sprintf ('% u', $ Hashnum );
- $ Length = strlen ($ HashStr );
- For ($ I = $ length-1; $ I> = 0; $ I -){
- $ Re = $ HashStr {$ I };
- If (1 ===( $ Flag % 2 )){
- $ Re + = $ Re;
- $ Re = (int) ($ Re/10) + ($ Re % 10 );
- }
- $ CheckByte + = $ Re;
- $ Flag ++;
- }
- $ CheckByte % = 10;
- If (0! ==$ CheckByte ){
- $ CheckByte = 10-$ CheckByte;
- If (1 ===( $ Flag % 2 )){
- If (1 ===( $ CheckByte % 2 )){
- $ CheckByte + = 9;
- }
- $ CheckByte >>=1;
- }
- }
- Return "7". $ CheckByte. $ HashStr;
- }
- // Return the pagerank checksum hash
- Function getch ($ url) {return CheckHash (HashURL ($ url ));}
- // Return the pagerank figure
- Function getpr ($ url ){
- Global $ googlehost, $ googleua;
- $ Pr = 0; // default return
- $ Ch = getch ($ url );
- $ Fp = fsockopen ($ googlehost, 80, $ errno, $ errstr, 30 );
- If ($ fp ){
- $ Out = "GET/search? Client = navclient-auto & ch = $ ch & features = Rank & q = info: $ url HTTP/1.1 \ r \ n ";
- // Echo"
$out \ N "; // debug only
- $ Out. = "User-Agent: $ googleua \ r \ n ";
- $ Out. = "Host: $ googlehost \ r \ n ";
- $ Out. = "Connection: Close \ r \ n ";
- Fwrite ($ fp, $ out );
- // $ Pagerank = substr (fgets ($ fp, 128), 4); // debug only
- // Echo $ pagerank; // debug only
- While (! Feof ($ fp )){
- $ Data = fgets ($ fp, 128 );
- // Echo $ data;
- $ Pos = strpos ($ data, "Rank _");
- If ($ pos = false) {} else {
- $ Pr = substr ($ data, $ pos + 9 );
- $ Pr = trim ($ pr );
- $ Pr = str_replace ("\ n", ", $ pr );
- Return $ pr;
- }
- }
- // Else {echo "$ errstr ($ errno) \ n";} // debug only
- Fclose ($ fp );
- }
- Return $ pr;
- }
- ?>
|