Google PR. How is it calculated?

General adult web master chat, help and information. Discuss any events and activities in the adult business (compare affiliate programs, talk over CJ/TGP scripts etc) SPAM is NOT allowed here!

Google PR. How is it calculated?

Postby smlbsns » Wed Nov 01, 2006 9:44 pm

I wonder what formula is used by Google to calculate a page rank for some particular page. Any ideas?
User avatar
smlbsns
FHG Board Member
 
Posts: 7
Joined: Sat Oct 21, 2006 7:31 am

Postby sowar » Wed Nov 01, 2006 9:57 pm

The Google PR formula is not a secret. See:

PR(A) = (1-d) + d(PR(t1)/C(t1) + ... + PR(tn)/C(tn))

Here PR(A) is the page rank boost your page A will get after being linked from someone else's site (t1). PR(t1) is the page rank of the page which links to you and C(t1) is the amount of total links that (t1) has.

Imagine your site was linked by someone's link page which had a PR of 4 and 9 other links, here's how the formula should look like:

PR(AKA) = (1-0.85) + 0.85*(4/10)
PR(AKA) = 0.15 + 0.85*(0.4)
PR(AKA) = 0.15 + 0.34
PR(AKA) = 0.49

0.85 above is damping factor - the amount of your PR which you can actually pass on when you link to another site.

To sum up my site would get an injection of 0.49 PR after being linked from a page with a PR of four and 9 other links.

Let's say you were linked from a site with a PR of 8, double the previous example's amount, which had 15 other links, a total of 16 outbound links, your boost would be:

PR(AKA) = (1-0.85) +0.85*(8/16)
PR(AKA) = 0.15 + 0.85(0.5)
PR(AKA) = 0.15 + 0.425
PR(AKA) = 0.575
sowar
FHG Board Member
 
Posts: 16
Joined: Mon Dec 13, 2004 9:32 pm

Postby omni56 » Wed Nov 01, 2006 10:20 pm

Here a good article about PR calculation: http://www.webworkshop.net/pagerank.html
User avatar
omni56
FHG Board Member
 
Posts: 81
Joined: Sun Nov 14, 2004 5:51 pm

Postby smlbsns » Wed Nov 01, 2006 11:58 pm

Thank you guys especially for the article at webworkshop.net, but is there any script what allows one to calculate/retrieve the page rank for a given url? I was searching for it but haven't found anything :(
User avatar
smlbsns
FHG Board Member
 
Posts: 7
Joined: Sat Oct 21, 2006 7:31 am

Postby sowar » Thu Nov 02, 2006 12:15 am

As far as I know there is no "legal" way to get pagerank for a list of sites/pages that do not violate the Google's rules. All the 3rd party scripts doing this are NOT obeying Google's ToS.
sowar
FHG Board Member
 
Posts: 16
Joined: Mon Dec 13, 2004 9:32 pm

Postby smutboy » Thu Nov 02, 2006 12:12 pm

You should always check hotscripts.com before to ask about any script on boards, because hotscripts.com has almost everything! So this is a link to php script which calculates google pr: http://hotscripts.com/Detailed/37856.html
User avatar
smutboy
FHG Board Member
 
Posts: 49
Joined: Thu Dec 02, 2004 11:09 pm

Postby smlbsns » Thu Nov 02, 2006 11:25 pm

Thanks for the url, but the script there is CRYPTED so I just can't see the source :(
User avatar
smlbsns
FHG Board Member
 
Posts: 7
Joined: Sat Oct 21, 2006 7:31 am

Postby smutboy » Fri Nov 03, 2006 8:42 pm

Replace eval by echo and run the script. Now look at the HTML source - encrypted junk turns into normal readable PHP code! :mrgreen:

P.S. I could post Google pr calculator code right here.
User avatar
smutboy
FHG Board Member
 
Posts: 49
Joined: Thu Dec 02, 2004 11:09 pm

Postby smlbsns » Mon Dec 11, 2006 10:45 pm

Still can't see a shit. The code is crypted! smutboy, send the encrypted code to my PM please.
User avatar
smlbsns
FHG Board Member
 
Posts: 7
Joined: Sat Oct 21, 2006 7:31 am

Postby smutboy » Tue Apr 24, 2007 1:54 pm

Ok, here we go:

Code: Select all
<?php
define('GOOGLE_MAGIC', 0xE6359A60);

//unsigned shift right
function zeroFill($a, $b)
{
    $z = hexdec(80000000);
        if ($z & $a)
        {
            $a = ($a>>1);
            $a &= (~$z);
            $a |= 0x40000000;
            $a = ($a>>($b-1));
        }
        else
        {
            $a = ($a>>$b);
        }
        return $a;
}


function mix($a,$b,$c) {
  $a -= $b;
  $a -= $c;
  $a ^= (zeroFill($c,13));

  $b -= $c; $b -= $a; $b ^= ($a<<8);
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
  $b -= $c; $b -= $a; $b ^= ($a<<16);
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));   
  $b -= $c; $b -= $a; $b ^= ($a<<10);
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
   
  return array($a,$b,$c);
}

function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
    if(is_null($length)) {
        $length = sizeof($url);
    }
    $a = $b = 0x9E3779B9;
    $c = $init;
    $k = 0;
    $len = $length;
    while($len >= 12) {
        $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
        $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
        $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
        $mix = mix($a,$b,$c);
        $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
        $k += 12;
        $len -= 12;
    }

    $c += $length;
    switch($len)              /* all the case statements fall through */
    {
        case 11: $c+=($url[$k+10]<<24);
        case 10: $c+=($url[$k+9]<<16);
        case 9 : $c+=($url[$k+8]<<8);
          /* the first byte of c is reserved for the length */
        case 8 : $b+=($url[$k+7]<<24);
        case 7 : $b+=($url[$k+6]<<16);
        case 6 : $b+=($url[$k+5]<<8);
        case 5 : $b+=($url[$k+4]);
        case 4 : $a+=($url[$k+3]<<24);
        case 3 : $a+=($url[$k+2]<<16);
        case 2 : $a+=($url[$k+1]<<8);
        case 1 : $a+=($url[$k+0]);
         /* case 0: nothing left to add */
    }
    $mix = mix($a,$b,$c);
    /*-------------------------------------------- report the result */
    return $mix[2];
}

//converts a string into an array of integers containing the numeric value of the char
function strord($string) {
    for($i=0;$i<strlen($string);$i++) {
        $result[$i] = ord($string{$i});
    }
    return $result;
}


// converts an array of 32 bit integers into an array with 8 bit values. Equivalent to (BYTE *)arr32

function c32to8bit($arr32) {
    for($i=0;$i<count($arr32);$i++) {
        for ($bitOrder=$i*4;$bitOrder<=$i*4+3;$bitOrder++) {
            $arr8[$bitOrder]=$arr32[$i]&255;
            $arr32[$i]=zeroFill($arr32[$i], 8);
        }     
    }
    return $arr8;
}


function GetGooglePR($url)
    {
    $url = 'info:'.$url;
    $ch = GoogleCH(strord($url));
    $ch = ((($ch/7) << 2) | (((int)fmod($ch,13))&7));
    $prbuf = array();
    $prbuf[0] = $ch;
    for($i = 1; $i < 20; $i++)
        {
        $prbuf[$i] = $prbuf[$i-1]-9;
        }
    $ch = GoogleCH(c32to8bit($prbuf), 80);
   
//    $ch=sprintf("%u", $ch);
    $HEAD = "GET /search?sourceid=navclient-ff&features=Rank&client=navclient-auto-ff&ch=".sprintf("6%u",$ch)."&q=".urlencode($url)." HTTP/1.1\r\n";
    $HEAD.= "Host: toolbarqueries.google.com\r\n";
    $HEAD.= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8) Gecko/20051111 Firefox/1.5\r\n";
    $HEAD.= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/"."*;q=0.5\r\n";
    $HEAD.= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
    $HEAD.= "Connection: Close\r\n";
    $HEAD.= "Cache-Control: max-age=0\r\n";
    $HEAD.= "Pragma: no-cache\r\n";
    $HEAD.= "Content-type: text/xml\r\n";
    $HEAD.= "\r\n";

$fp = fsockopen("toolbarqueries.google.com", "80", $errno, $errstr, 10);
    if (!$fp)
        {
        echo "$errstr ($errno)<br />\n";
        return "";
        }
    else
        {
        fputs($fp, $HEAD);
        $Result="";
        while (!feof($fp))
            {
            $Result.=fgets($fp, 4096);
            }
        fclose($fp);
        }
       
    if(strpos($Result,"Rank_"))
        {
        $Result=substr($Result,strpos($Result,"Rank_")+5);
        $Result=trim(substr($Result,strpos($Result,":")+1));
        $Result=trim(substr($Result,strpos($Result,":")+1));
        $Result=trim(substr($Result,0,strpos($Result,"\n")));
        }
    else
        $Result=-1;
           
    return $Result;
    }
echo GetGooglePR("http://yourdomain.com");
?>
User avatar
smutboy
FHG Board Member
 
Posts: 49
Joined: Thu Dec 02, 2004 11:09 pm

Re: Google PR. How is it calculated?

Postby cyberxxx » Sun Jul 11, 2010 8:20 pm

Here is a new working code:

Code: Select all
<?php
class PageRank
{
   /*
    * convert a string to a 32-bit integer
    */
   function ConvertStrToInt($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));
           }
           $Check += ord($Str{$i});
       }
       return $Check;
   }

   /*
    * Genearate a hash for a url
    */
   function HashURL($String)
   {
       $Check1 = $this->ConvertStrToInt($String, 0x1505, 0x21);
       $Check2 = $this->ConvertStrToInt($String, 0, 0x1003F);

       $Check1 >>= 2;
       $Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
       $Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
       $Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);

       $T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F );
       $T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );

       return ($T1 | $T2);
   }

   /*
    * genearate a checksum for the hash string
    */
   function CheckHash($Hashnum)
   {
       $CheckByte = 0;
       $Flag = false;

       $HashStr = sprintf('%u', $Hashnum) ;
       $length = strlen($HashStr);

       for ($i = $length - 1;  $i >= 0;  $i --) {
           $Re = $HashStr{$i};
           if ($Flag) {
               $Re += $Re;
               $Re = (int)($Re / 10) + ($Re % 10);
           }
           $CheckByte += $Re;
           $Flag = !$Flag;
       }

       $CheckByte %= 10;
       if (0 !== $CheckByte) {
           $CheckByte = 10 - $CheckByte;
           if ($Flag) {
               if (1 === ($CheckByte % 2)) {
                   $CheckByte += 9;
               }
               $CheckByte >>= 1;
           }
       }

       return '7'.$CheckByte.$HashStr;
   }

   function getRank($url)
   {
      //$ch = "6" . $this->GoogleCH($this->strord("info:" . $url));
      $ch = $this->CheckHash($this->HashURL($url));
      $pagerank = -1;
      $fp = fsockopen("www.google.com", 80, $errno, $errstr, 10);
      if (!$fp)
      {
         echo "$errstr ($errno)<br />\n";
      }
      else
      {
         $out = "GET /search?client=navclient-auto&ch=" . $ch . "&features=Rank&q=info:" . $url . " HTTP/1.1\r\n";
         $out .= "Host: google.com\r\n";
         $out .= "Connection: Close\r\n\r\n";
         fwrite($fp, $out);
         while (!feof($fp))
         {
            //stream_set_timeout($fp, 10);
            $data = fgets($fp, 128);
            $pos = strpos($data, "Rank_");
            if ($pos === false)
            {
            }
            else
            {
               $pagerank = trim(substr($data, $pos +9));
            }
         }
         fclose($fp);
      }
      return $pagerank;
   }
}

$url = 'http://google.com/';

$pr = new PageRank();
$result = $pr->getRank($url);

?>
CyberSEO Suite - make your syndicated posts unique, remove the dupes, turn your blog into a powerful morphing RSS host
Morphing Feeds - the most popular hosted blog and morphing RSS software solution from an author of morphing feeds term
User avatar
cyberxxx
Site Admin
 
Posts: 307
Joined: Sun Nov 14, 2004 7:01 am
Location: /root


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron