Google PageRank Script in PHP (Open Source)

  • cyberax
  • Graduate
  • Graduate
  • User avatar
  • Posts: 169
  • Loc: INDIA

Post 3+ Months Ago

Hi Guys,

All of you who are looking for the PHP Script (Source Code) to get the PageRank programmitically can now get it from:

The Google Pagerank Checksum Calculator by Alex Stapleton
// dead link removed

Google PagerankGET 0.1 By ZeNiTRaM
// dead link removed

This was made possible at MobileRead Forum
http://www.mobileread.com/forums/showthread.php?t=1670


Now I am looking for an ASP version (VBScript) for the same. Anyone who is interested can come up for a joint development.

Cheers to All !!!
Moderator Remark: dead links removed
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • cyberax
  • Graduate
  • Graduate
  • User avatar
  • Posts: 169
  • Loc: INDIA

Post 3+ Months Ago

I am sorry if I missed to name gemini for his input.


http://www.mobileread.com/forums/showthread.php?t=1670&page=7&pp=15



Regards,
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9088
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Very nice. Looks like there was a great deal of solid effort going on over there at mobileread. I am sure news will spread fast and Google will have to do something so that people continue to use their toolbar (Like modify how the toolbar retreives the checksum so everyone's code no longer works). However I really do think no matter what they try somebody will be able to figure out the new algorithm. One nice thing about this is that people won't be able to sell this code for a great deal of money anymore.
  • rtchar
  • Expert
  • Expert
  • User avatar
  • Posts: 606
  • Loc: Canada

Post 3+ Months Ago

cyberax

Did I hear there was a PERL port some where?

I would be interested in doing that if it isn't already finished.
  • dprichard
  • Beginner
  • Beginner
  • User avatar
  • Posts: 61
  • Loc: Clearwater Florida

Post 3+ Months Ago

Aren't there search engines that already show results with page rank? Not wanting to step on anyones toes, but what is the advantage of looking it up this way over looking it up on a seach engine like this?

// dead link removed

Not trying to diss anyone... Legit question...
Moderator Remark: dead links removed
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

The advantage of looking it up yourself is that you can incorporate it into your own scripts. Not everybody wants/needs it in search results.
  • rtchar
  • Expert
  • Expert
  • User avatar
  • Posts: 606
  • Loc: Canada

Post 3+ Months Ago

I agree with Axe ... it would make searching for backlinks a lot more efficient for me.

Prog is good for looking at competitors backlinks. It lets me identify high PR sites to contact. But we know that Google does not show ALL the links. I would be 2 months behind my competitors if that was my only source of information.

I wrote a link harvester program, but I still have to paste links into a PR lookup page (50 at a time) to find the top links.

But thanks to this forum that will be fixed soon! :)
  • dprichard
  • Beginner
  • Beginner
  • User avatar
  • Posts: 61
  • Loc: Clearwater Florida

Post 3+ Months Ago

Good thought... I never thought about making a page with all my pages and their rank... I knew you guys would see more potential then I would.
  • acidophil
  • Born
  • Born
  • acidophil
  • Posts: 1

Post 3+ Months Ago

hi cyberax, hi phorum!

i've seen a lot of scripts last 3 days
but, sorry cyberax, none was in asp :(
i found c, python, pascal, varrities of php and win/pc binaries...


hmmm and i'am tooooo lazy to port it to perl / cgi...

so if someone have had done this please post here and/or pm me!!!
i'll post links to the sources i found if someone is interested in.

c'u
acidophil
  • helohelo
  • Born
  • Born
  • helohelo
  • Posts: 3

Post 3+ Months Ago

Hi Cyberax,
can you please explain how to use the code thats provided on //dead-link-removed ?

Its totally wrapped.
Do I need other files then that one?
the form is not posting or getting anything, i do not understand...

a php rooky
Moderator Remark: dead links removed
  • rtchar
  • Expert
  • Expert
  • User avatar
  • Posts: 606
  • Loc: Canada

Post 3+ Months Ago

Do you have installed on a PHP capable server?

Browsers are not able to decode PHP files.
  • helohelo
  • Born
  • Born
  • helohelo
  • Posts: 3

Post 3+ Months Ago

yes,
what I need is a summery for php rookies.
what to install where as what.
-should I save the code as php file?
-on the main form I do not see any include nor link nor formlink
How is the url input put to the script and tranfered back?
As you see, all rookie questions.... :?
  • rtchar
  • Expert
  • Expert
  • User avatar
  • Posts: 606
  • Loc: Canada

Post 3+ Months Ago

When I installed the code ...

I copied the source code and saved it as a PHP file in my scripts (cgi-bin) directory. Then I did a view source on the form page and saved that as an HTML file in the root directory.

A couple of minor source changes to the form html (to suit my site) and it was working.
  • helohelo
  • Born
  • Born
  • helohelo
  • Posts: 3

Post 3+ Months Ago

rtchar wrote:
A couple of minor source changes to the form html (to suit my site) and it was working.

what lines of code I have to chance?
  • rtchar
  • Expert
  • Expert
  • User avatar
  • Posts: 606
  • Loc: Canada

Post 3+ Months Ago

The only change would be in the HTML

<form method="get" action="PATH TO PHP FILE.php">
  • Pavel
  • Newbie
  • Newbie
  • Pavel
  • Posts: 11

Post 3+ Months Ago

I am trying to use the php script for the pagerank calculator from this site: // dead link removed

I was trying to use the script that he posted up on his site, I copy and paste that script into Microsoft Frontpage, and then I save it as pagerank.php and after it loads, it just shows me the script !!! It does not calculate.

But when i use his pagerank.php which I must download, it works ! It is just the script i was looking at before but encoded ! Why does that one work ????? Is it becuase I am opening it in FrontPage ???

Ok and now I just did it all over but using notepad, still doesn't work, it just shows all the wierd script language and stuff..
Moderator Remark: dead links removed
  • BartAfterDark
  • Graduate
  • Graduate
  • BartAfterDark
  • Posts: 120

Post 3+ Months Ago

RTFM :study:
Installation

All you have to do is upload pagerank.php to your web server.

Call it like this: http://www.example.com/pagerank.php?url=http://www.yahoo.com/

... where example.com is your website and yahoo.com is the website to get the PR of.
  • Pavel
  • Newbie
  • Newbie
  • Pavel
  • Posts: 11

Post 3+ Months Ago

Yes the pagerank.php works, I know, but there are a few things that I need to change, and I cannot change the pagerank.php becuase it is encrypted, so I am trying to make the source code for pagerank.php work, but it is not working, I was hoping someone here can tell me why.
  • rtchar
  • Expert
  • Expert
  • User avatar
  • Posts: 606
  • Loc: Canada

Post 3+ Months Ago

Since the site is gone --- here is source from original post:

PHP Code: [ Select ]
<?php
/*
// Google PageRank Calculator function by ZeNiTRaM
// Licensed under the GPL License
// Uses code from The Google Checksum Calculator, by Alex Stapleton, Andy Doctorow, Vijay "Cyberax" Bhatter, and a few others, licensed under the public domain (http://www.mobileread.com/forums/showpost.php?p=7769&postcount=87) and XMLize.php by Hans Anderson (http://www.hansanderson.com/php/xml/).
// Use: $pagerank = GetPagerank("http://www.google.es");
*/
function GetPagerank($urlo) {
define('GOOGLE_MAGIC', 0xE6359A60);
function xmlize($data, $WHITE=1) {
 
    $data = trim($data);
    $vals = $index = $array = array();
    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $WHITE);
    if ( !xml_parse_into_struct($parser, $data, $vals, $index) )
    {
   die(sprintf("XML error: %s at line %d",
                    xml_error_string(xml_get_error_code($parser)),
                    xml_get_current_line_number($parser)));
 
    }
    xml_parser_free($parser);
 
    $i = 0;
 
    $tagname = $vals[$i]['tag'];
    if ( isset ($vals[$i]['attributes'] ) )
    {
        $array[$tagname]['@'] = $vals[$i]['attributes'];
    } else {
        $array[$tagname]['@'] = array();
    }
 
    $array[$tagname]["#"] = xml_depth($vals, $i);
 
    return $array;
}
 
/*
 *
 * You don't need to do anything with this function, it's called by
 * xmlize.  It's a recursive function, calling itself as it goes deeper
 * into the xml levels.  If you make any improvements, please let me know.
 *
 *
 */
 
function xml_depth($vals, &$i) {
    $children = array();
 
    if ( isset($vals[$i]['value']) )
    {
        array_push($children, $vals[$i]['value']);
    }
 
    while (++$i < count($vals)) {
 
        switch ($vals[$i]['type']) {
 
           case 'open':
 
                if ( isset ( $vals[$i]['tag'] ) )
                {
                    $tagname = $vals[$i]['tag'];
                } else {
                    $tagname = '';
                }
 
                if ( isset ( $children[$tagname] ) )
                {
                    $size = sizeof($children[$tagname]);
                } else {
                    $size = 0;
                }
 
                if ( isset ( $vals[$i]['attributes'] ) ) {
                    $children[$tagname][$size]['@'] = $vals[$i]["attributes"];
                }
 
                $children[$tagname][$size]['#'] = xml_depth($vals, $i);
 
            break;
 
 
            case 'cdata':
                array_push($children, $vals[$i]['value']);
            break;
 
            case 'complete':
                $tagname = $vals[$i]['tag'];
 
                if( isset ($children[$tagname]) )
                {
                    $size = sizeof($children[$tagname]);
                } else {
                    $size = 0;
                }
 
                if( isset ( $vals[$i]['value'] ) )
                {
                    $children[$tagname][$size]["#"] = $vals[$i]['value'];
                } else {
                    $children[$tagname][$size]["#"] = '';
                }
 
                if ( isset ($vals[$i]['attributes']) ) {
                    $children[$tagname][$size]['@']
                                             = $vals[$i]['attributes'];
                }      
 
            break;
 
            case 'close':
                return $children;
            break;
        }
 
    }
 
   return $children;
 
}
 
 
/* function by acebone@f2s.com, a HUGE help!
 *
 * this helps you understand the structure of the array xmlize() outputs
 *
 * usage:
 * traverse_xmlize($xml, 'xml_');
 * print '<pre>' . implode("", $traverse_array . '</pre>';
 *
 *
 */
 
function traverse_xmlize($array, $arrName = "array", $level = 0) {
 
    foreach($array as $key=>$val)
    {
        if ( is_array($val) )
        {
            traverse_xmlize($val, $arrName . "[" . $key . "]", $level + 1);
        } else {
            $GLOBALS['traverse_array'][] = '$' . $arrName . '[' . $key . '] = "' . $val . "\"\n";
        }
    }
 
    return 1;
 
}
 
//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;
}
 
$url = 'info:'.$urlo;
$ch = GoogleCH(strord($url));
$chf = "6$ch";
 
$file = file("http://www.google.com/search?client=navclient-auto&ch=$chf&q=$url");
$file_str = implode("", $file);
         $xml = xmlize($file_str);
 
$pr = $xml["GSP"]["#"]["RES"][0]["#"]["R"][0]["#"]["RK"][0]["#"];
return $pr;
}
?>
  1. <?php
  2. /*
  3. // Google PageRank Calculator function by ZeNiTRaM
  4. // Licensed under the GPL License
  5. // Uses code from The Google Checksum Calculator, by Alex Stapleton, Andy Doctorow, Vijay "Cyberax" Bhatter, and a few others, licensed under the public domain (http://www.mobileread.com/forums/showpost.php?p=7769&postcount=87) and XMLize.php by Hans Anderson (http://www.hansanderson.com/php/xml/).
  6. // Use: $pagerank = GetPagerank("http://www.google.es");
  7. */
  8. function GetPagerank($urlo) {
  9. define('GOOGLE_MAGIC', 0xE6359A60);
  10. function xmlize($data, $WHITE=1) {
  11.  
  12.     $data = trim($data);
  13.     $vals = $index = $array = array();
  14.     $parser = xml_parser_create();
  15.     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  16.     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $WHITE);
  17.     if ( !xml_parse_into_struct($parser, $data, $vals, $index) )
  18.     {
  19.    die(sprintf("XML error: %s at line %d",
  20.                     xml_error_string(xml_get_error_code($parser)),
  21.                     xml_get_current_line_number($parser)));
  22.  
  23.     }
  24.     xml_parser_free($parser);
  25.  
  26.     $i = 0;
  27.  
  28.     $tagname = $vals[$i]['tag'];
  29.     if ( isset ($vals[$i]['attributes'] ) )
  30.     {
  31.         $array[$tagname]['@'] = $vals[$i]['attributes'];
  32.     } else {
  33.         $array[$tagname]['@'] = array();
  34.     }
  35.  
  36.     $array[$tagname]["#"] = xml_depth($vals, $i);
  37.  
  38.     return $array;
  39. }
  40.  
  41. /*
  42.  *
  43.  * You don't need to do anything with this function, it's called by
  44.  * xmlize.  It's a recursive function, calling itself as it goes deeper
  45.  * into the xml levels.  If you make any improvements, please let me know.
  46.  *
  47.  *
  48.  */
  49.  
  50. function xml_depth($vals, &$i) {
  51.     $children = array();
  52.  
  53.     if ( isset($vals[$i]['value']) )
  54.     {
  55.         array_push($children, $vals[$i]['value']);
  56.     }
  57.  
  58.     while (++$i < count($vals)) {
  59.  
  60.         switch ($vals[$i]['type']) {
  61.  
  62.            case 'open':
  63.  
  64.                 if ( isset ( $vals[$i]['tag'] ) )
  65.                 {
  66.                     $tagname = $vals[$i]['tag'];
  67.                 } else {
  68.                     $tagname = '';
  69.                 }
  70.  
  71.                 if ( isset ( $children[$tagname] ) )
  72.                 {
  73.                     $size = sizeof($children[$tagname]);
  74.                 } else {
  75.                     $size = 0;
  76.                 }
  77.  
  78.                 if ( isset ( $vals[$i]['attributes'] ) ) {
  79.                     $children[$tagname][$size]['@'] = $vals[$i]["attributes"];
  80.                 }
  81.  
  82.                 $children[$tagname][$size]['#'] = xml_depth($vals, $i);
  83.  
  84.             break;
  85.  
  86.  
  87.             case 'cdata':
  88.                 array_push($children, $vals[$i]['value']);
  89.             break;
  90.  
  91.             case 'complete':
  92.                 $tagname = $vals[$i]['tag'];
  93.  
  94.                 if( isset ($children[$tagname]) )
  95.                 {
  96.                     $size = sizeof($children[$tagname]);
  97.                 } else {
  98.                     $size = 0;
  99.                 }
  100.  
  101.                 if( isset ( $vals[$i]['value'] ) )
  102.                 {
  103.                     $children[$tagname][$size]["#"] = $vals[$i]['value'];
  104.                 } else {
  105.                     $children[$tagname][$size]["#"] = '';
  106.                 }
  107.  
  108.                 if ( isset ($vals[$i]['attributes']) ) {
  109.                     $children[$tagname][$size]['@']
  110.                                              = $vals[$i]['attributes'];
  111.                 }      
  112.  
  113.             break;
  114.  
  115.             case 'close':
  116.                 return $children;
  117.             break;
  118.         }
  119.  
  120.     }
  121.  
  122.    return $children;
  123.  
  124. }
  125.  
  126.  
  127. /* function by acebone@f2s.com, a HUGE help!
  128.  *
  129.  * this helps you understand the structure of the array xmlize() outputs
  130.  *
  131.  * usage:
  132.  * traverse_xmlize($xml, 'xml_');
  133.  * print '<pre>' . implode("", $traverse_array . '</pre>';
  134.  *
  135.  *
  136.  */
  137.  
  138. function traverse_xmlize($array, $arrName = "array", $level = 0) {
  139.  
  140.     foreach($array as $key=>$val)
  141.     {
  142.         if ( is_array($val) )
  143.         {
  144.             traverse_xmlize($val, $arrName . "[" . $key . "]", $level + 1);
  145.         } else {
  146.             $GLOBALS['traverse_array'][] = '$' . $arrName . '[' . $key . '] = "' . $val . "\"\n";
  147.         }
  148.     }
  149.  
  150.     return 1;
  151.  
  152. }
  153.  
  154. //unsigned shift right
  155. function zeroFill($a, $b)
  156. {
  157.     $z = hexdec(80000000);
  158.         if ($z & $a)
  159.         {
  160.             $a = ($a>>1);
  161.             $a &= (~$z);
  162.             $a |= 0x40000000;
  163.             $a = ($a>>($b-1));
  164.         }
  165.         else
  166.         {
  167.             $a = ($a>>$b);
  168.         }
  169.         return $a;
  170. }
  171.  
  172.  
  173. function mix($a,$b,$c) {
  174.   $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
  175.   $b -= $c; $b -= $a; $b ^= ($a<<8);
  176.   $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
  177.   $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
  178.   $b -= $c; $b -= $a; $b ^= ($a<<16);
  179.   $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
  180.   $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));  
  181.   $b -= $c; $b -= $a; $b ^= ($a<<10);
  182.   $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
  183.  
  184.   return array($a,$b,$c);
  185. }
  186.  
  187. function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
  188.     if(is_null($length)) {
  189.         $length = sizeof($url);
  190.     }
  191.     $a = $b = 0x9E3779B9;
  192.     $c = $init;
  193.     $k = 0;
  194.     $len = $length;
  195.     while($len >= 12) {
  196.         $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
  197.         $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
  198.         $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
  199.         $mix = mix($a,$b,$c);
  200.         $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
  201.         $k += 12;
  202.         $len -= 12;
  203.     }
  204.  
  205.     $c += $length;
  206.     switch($len)              /* all the case statements fall through */
  207.     {
  208.         case 11: $c+=($url[$k+10]<<24);
  209.         case 10: $c+=($url[$k+9]<<16);
  210.         case 9 : $c+=($url[$k+8]<<8);
  211.           /* the first byte of c is reserved for the length */
  212.         case 8 : $b+=($url[$k+7]<<24);
  213.         case 7 : $b+=($url[$k+6]<<16);
  214.         case 6 : $b+=($url[$k+5]<<8);
  215.         case 5 : $b+=($url[$k+4]);
  216.         case 4 : $a+=($url[$k+3]<<24);
  217.         case 3 : $a+=($url[$k+2]<<16);
  218.         case 2 : $a+=($url[$k+1]<<8);
  219.         case 1 : $a+=($url[$k+0]);
  220.          /* case 0: nothing left to add */
  221.     }
  222.     $mix = mix($a,$b,$c);
  223.     /*-------------------------------------------- report the result */
  224.     return $mix[2];
  225. }
  226.  
  227. //converts a string into an array of integers containing the numeric value of the char
  228. function strord($string) {
  229.     for($i=0;$i<strlen($string);$i++) {
  230.         $result[$i] = ord($string{$i});
  231.     }
  232.     return $result;
  233. }
  234.  
  235. $url = 'info:'.$urlo;
  236. $ch = GoogleCH(strord($url));
  237. $chf = "6$ch";
  238.  
  239. $file = file("http://www.google.com/search?client=navclient-auto&ch=$chf&q=$url");
  240. $file_str = implode("", $file);
  241.          $xml = xmlize($file_str);
  242.  
  243. $pr = $xml["GSP"]["#"]["RES"][0]["#"]["R"][0]["#"]["RK"][0]["#"];
  244. return $pr;
  245. }
  246. ?>
Moderator Remark: fixed code block
  • Pavel
  • Newbie
  • Newbie
  • Pavel
  • Posts: 11

Post 3+ Months Ago

I just tried that script, it did not work, it just opened the file pagerank.php and it did not do the calculation..
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9088
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Hi Pavel,

Make sure line 5 on the code above:

Code: [ Select ]
(http://www.mobileread.com/forums/showpost.php?p=7769&postcount=87) and XMLize.php by Hans Anderson (http://www.hansanderson.com/php/xml/).


is commented out with a //

It appears the code he pasted in there was all on one line, but due to wrapping on the forum it ended up on two lines. So if you copied it exactly as you see it above, that would cause a problem for you.
  • Pavel
  • Newbie
  • Newbie
  • Pavel
  • Posts: 11

Post 3+ Months Ago

ok my final code looks like this:

Code: [ Select ]
<?php
// Google PageRank Calculator function by ZeNiTRaM
// Licensed under the GPL License
// Uses code from The Google Checksum Calculator, by Alex Stapleton, Andy Doctorow, Vijay "Cyberax" Bhatter, and a few others, licensed under the public domain (http://www.mobileread.com/forums/showpost.php?p=7769&postcount=87) and XMLize.php by Hans Anderson (http://www.hansanderson.com/php/xml/).
(http://www.mobileread.com/forums/showpost.php?p=7769&postcount=87) and XMLize.php by Hans Anderson (http://www.hansanderson.com/php/xml/).
// Use: $pagerank = GetPagerank("http://www.google.es");

function GetPagerank($urlo) {
define('GOOGLE_MAGIC', 0xE6359A60);
function xmlize($data, $WHITE=1) {

$data = trim($data);
$vals = $index = $array = array();
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $WHITE);
if ( !xml_parse_into_struct($parser, $data, $vals, $index) )
{
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));

}
xml_parser_free($parser);

$i = 0;

$tagname = $vals[$i]['tag'];
if ( isset ($vals[$i]['attributes'] ) )
{
$array[$tagname]['@'] = $vals[$i]['attributes'];
} else {
$array[$tagname]['@'] = array();
}

$array[$tagname]["#"] = xml_depth($vals, $i);

return $array;
}

/*
*
* You don't need to do anything with this function, it's called by
* xmlize. It's a recursive function, calling itself as it goes deeper
* into the xml levels. If you make any improvements, please let me know.
*
*
*/

function xml_depth($vals, &$i) {
$children = array();

if ( isset($vals[$i]['value']) )
{
array_push($children, $vals[$i]['value']);
}

while (++$i < count($vals)) {

switch ($vals[$i]['type']) {

case 'open':

if ( isset ( $vals[$i]['tag'] ) )
{
$tagname = $vals[$i]['tag'];
} else {
$tagname = '';
}

if ( isset ( $children[$tagname] ) )
{
$size = sizeof($children[$tagname]);
} else {
$size = 0;
}

if ( isset ( $vals[$i]['attributes'] ) ) {
$children[$tagname][$size]['@'] = $vals[$i]["attributes"];
}

$children[$tagname][$size]['#'] = xml_depth($vals, $i);

break;


case 'cdata':
array_push($children, $vals[$i]['value']);
break;

case 'complete':
$tagname = $vals[$i]['tag'];

if( isset ($children[$tagname]) )
{
$size = sizeof($children[$tagname]);
} else {
$size = 0;
}

if( isset ( $vals[$i]['value'] ) )
{
$children[$tagname][$size]["#"] = $vals[$i]['value'];
} else {
$children[$tagname][$size]["#"] = '';
}

if ( isset ($vals[$i]['attributes']) ) {
$children[$tagname][$size]['@']
= $vals[$i]['attributes'];
}

break;

case 'close':
return $children;
break;
}

}

return $children;

}


/* function by acebone@f2s.com, a HUGE help!
*
* this helps you understand the structure of the array xmlize() outputs
*
* usage:
* traverse_xmlize($xml, 'xml_');
* print '<pre>' . implode("", $traverse_array . '</pre>';
*
*
*/

function traverse_xmlize($array, $arrName = "array", $level = 0) {

foreach($array as $key=>$val)
{
if ( is_array($val) )
{
traverse_xmlize($val, $arrName . "[" . $key . "]", $level + 1);
} else {
$GLOBALS['traverse_array'][] = '$' . $arrName . '[' . $key . '] = "' . $val . "\"\n";
}
}

return 1;

}

//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;
}

$url = 'info:'.$urlo;
$ch = GoogleCH(strord($url));
$chf = "6$ch";

$file = file("http://www.google.com/search?client=navclient-auto&ch=$chf&q=$url");
$file_str = implode("", $file);
$xml = xmlize($file_str);

$pr = $xml["GSP"]["#"]["RES"][0]["#"]["R"][0]["#"]["RK"][0]["#"];
return $pr;
}
?>
  1. <?php
  2. // Google PageRank Calculator function by ZeNiTRaM
  3. // Licensed under the GPL License
  4. // Uses code from The Google Checksum Calculator, by Alex Stapleton, Andy Doctorow, Vijay "Cyberax" Bhatter, and a few others, licensed under the public domain (http://www.mobileread.com/forums/showpost.php?p=7769&postcount=87) and XMLize.php by Hans Anderson (http://www.hansanderson.com/php/xml/).
  5. (http://www.mobileread.com/forums/showpost.php?p=7769&postcount=87) and XMLize.php by Hans Anderson (http://www.hansanderson.com/php/xml/).
  6. // Use: $pagerank = GetPagerank("http://www.google.es");
  7. function GetPagerank($urlo) {
  8. define('GOOGLE_MAGIC', 0xE6359A60);
  9. function xmlize($data, $WHITE=1) {
  10. $data = trim($data);
  11. $vals = $index = $array = array();
  12. $parser = xml_parser_create();
  13. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  14. xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $WHITE);
  15. if ( !xml_parse_into_struct($parser, $data, $vals, $index) )
  16. {
  17. die(sprintf("XML error: %s at line %d",
  18. xml_error_string(xml_get_error_code($parser)),
  19. xml_get_current_line_number($parser)));
  20. }
  21. xml_parser_free($parser);
  22. $i = 0;
  23. $tagname = $vals[$i]['tag'];
  24. if ( isset ($vals[$i]['attributes'] ) )
  25. {
  26. $array[$tagname]['@'] = $vals[$i]['attributes'];
  27. } else {
  28. $array[$tagname]['@'] = array();
  29. }
  30. $array[$tagname]["#"] = xml_depth($vals, $i);
  31. return $array;
  32. }
  33. /*
  34. *
  35. * You don't need to do anything with this function, it's called by
  36. * xmlize. It's a recursive function, calling itself as it goes deeper
  37. * into the xml levels. If you make any improvements, please let me know.
  38. *
  39. *
  40. */
  41. function xml_depth($vals, &$i) {
  42. $children = array();
  43. if ( isset($vals[$i]['value']) )
  44. {
  45. array_push($children, $vals[$i]['value']);
  46. }
  47. while (++$i < count($vals)) {
  48. switch ($vals[$i]['type']) {
  49. case 'open':
  50. if ( isset ( $vals[$i]['tag'] ) )
  51. {
  52. $tagname = $vals[$i]['tag'];
  53. } else {
  54. $tagname = '';
  55. }
  56. if ( isset ( $children[$tagname] ) )
  57. {
  58. $size = sizeof($children[$tagname]);
  59. } else {
  60. $size = 0;
  61. }
  62. if ( isset ( $vals[$i]['attributes'] ) ) {
  63. $children[$tagname][$size]['@'] = $vals[$i]["attributes"];
  64. }
  65. $children[$tagname][$size]['#'] = xml_depth($vals, $i);
  66. break;
  67. case 'cdata':
  68. array_push($children, $vals[$i]['value']);
  69. break;
  70. case 'complete':
  71. $tagname = $vals[$i]['tag'];
  72. if( isset ($children[$tagname]) )
  73. {
  74. $size = sizeof($children[$tagname]);
  75. } else {
  76. $size = 0;
  77. }
  78. if( isset ( $vals[$i]['value'] ) )
  79. {
  80. $children[$tagname][$size]["#"] = $vals[$i]['value'];
  81. } else {
  82. $children[$tagname][$size]["#"] = '';
  83. }
  84. if ( isset ($vals[$i]['attributes']) ) {
  85. $children[$tagname][$size]['@']
  86. = $vals[$i]['attributes'];
  87. }
  88. break;
  89. case 'close':
  90. return $children;
  91. break;
  92. }
  93. }
  94. return $children;
  95. }
  96. /* function by acebone@f2s.com, a HUGE help!
  97. *
  98. * this helps you understand the structure of the array xmlize() outputs
  99. *
  100. * usage:
  101. * traverse_xmlize($xml, 'xml_');
  102. * print '<pre>' . implode("", $traverse_array . '</pre>';
  103. *
  104. *
  105. */
  106. function traverse_xmlize($array, $arrName = "array", $level = 0) {
  107. foreach($array as $key=>$val)
  108. {
  109. if ( is_array($val) )
  110. {
  111. traverse_xmlize($val, $arrName . "[" . $key . "]", $level + 1);
  112. } else {
  113. $GLOBALS['traverse_array'][] = '$' . $arrName . '[' . $key . '] = "' . $val . "\"\n";
  114. }
  115. }
  116. return 1;
  117. }
  118. //unsigned shift right
  119. function zeroFill($a, $b)
  120. {
  121. $z = hexdec(80000000);
  122. if ($z & $a)
  123. {
  124. $a = ($a>>1);
  125. $a &= (~$z);
  126. $a |= 0x40000000;
  127. $a = ($a>>($b-1));
  128. }
  129. else
  130. {
  131. $a = ($a>>$b);
  132. }
  133. return $a;
  134. }
  135. function mix($a,$b,$c) {
  136. $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
  137. $b -= $c; $b -= $a; $b ^= ($a<<8);
  138. $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
  139. $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
  140. $b -= $c; $b -= $a; $b ^= ($a<<16);
  141. $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
  142. $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));
  143. $b -= $c; $b -= $a; $b ^= ($a<<10);
  144. $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
  145. return array($a,$b,$c);
  146. }
  147. function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
  148. if(is_null($length)) {
  149. $length = sizeof($url);
  150. }
  151. $a = $b = 0x9E3779B9;
  152. $c = $init;
  153. $k = 0;
  154. $len = $length;
  155. while($len >= 12) {
  156. $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
  157. $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
  158. $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
  159. $mix = mix($a,$b,$c);
  160. $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
  161. $k += 12;
  162. $len -= 12;
  163. }
  164. $c += $length;
  165. switch($len) /* all the case statements fall through */
  166. {
  167. case 11: $c+=($url[$k+10]<<24);
  168. case 10: $c+=($url[$k+9]<<16);
  169. case 9 : $c+=($url[$k+8]<<8);
  170. /* the first byte of c is reserved for the length */
  171. case 8 : $b+=($url[$k+7]<<24);
  172. case 7 : $b+=($url[$k+6]<<16);
  173. case 6 : $b+=($url[$k+5]<<8);
  174. case 5 : $b+=($url[$k+4]);
  175. case 4 : $a+=($url[$k+3]<<24);
  176. case 3 : $a+=($url[$k+2]<<16);
  177. case 2 : $a+=($url[$k+1]<<8);
  178. case 1 : $a+=($url[$k+0]);
  179. /* case 0: nothing left to add */
  180. }
  181. $mix = mix($a,$b,$c);
  182. /*-------------------------------------------- report the result */
  183. return $mix[2];
  184. }
  185. //converts a string into an array of integers containing the numeric value of the char
  186. function strord($string) {
  187. for($i=0;$i<strlen($string);$i++) {
  188. $result[$i] = ord($string{$i});
  189. }
  190. return $result;
  191. }
  192. $url = 'info:'.$urlo;
  193. $ch = GoogleCH(strord($url));
  194. $chf = "6$ch";
  195. $file = file("http://www.google.com/search?client=navclient-auto&ch=$chf&q=$url");
  196. $file_str = implode("", $file);
  197. $xml = xmlize($file_str);
  198. $pr = $xml["GSP"]["#"]["RES"][0]["#"]["R"][0]["#"]["RK"][0]["#"];
  199. return $pr;
  200. }
  201. ?>


and when i try to use it I get this error:

Quote:
Parse error: parse error, unexpected ':' in /home/virtual/site352/fst/var/www/html/pagerank.php on line 5
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9088
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Did you read my last post? From what I see you still did not comment out line 5.
  • Pavel
  • Newbie
  • Newbie
  • Pavel
  • Posts: 11

Post 3+ Months Ago

I am really sorry, I am extremelly knew to this, I did try to take out the // from line 5 (// Use: $pagerank = GetPagerank("http://www.google.es"); ), then i got alot of errors come up, and.. could you please show me what you I should put in ?
  • Pavel
  • Newbie
  • Newbie
  • Pavel
  • Posts: 11

Post 3+ Months Ago

I am not quite sure what you mean by "comment out" did you want me to remove the // on line 5, the line with the "$google" thing like that?

And I understand how on the forum it is 3 lines or so, but when i copy pasted it into notepad it all became one line.. when i loaded his exact code, it didn't give me errors, just didn't load up, gave me a blank screen. Could you please show me what you want me to put in or take out of line 5, or whatever needs to be done??
  • rtchar
  • Expert
  • Expert
  • User avatar
  • Posts: 606
  • Loc: Canada

Post 3+ Months Ago

The original code I posted is wrapped and pastes OK into my text editor so I don't think that is the problem...

This script is designed to RETURN the Page Rank to a calling function ... if you call it directly all you get is a blank screen.

Try this ....
1. Copy/Paste code to a text editor ...

2. Add the following lines ... at line 6 (just above the first function)
$pagerank = GetPagerank("http://www.google.es");
echo("PR=$pagerank");

3. Save the file as pagerank.php

4. FTP file to PHP enabled server

5. In browser type http://www.yourserver.com/pagerank.php
  • Pavel
  • Newbie
  • Newbie
  • Pavel
  • Posts: 11

Post 3+ Months Ago

The good news is that is works, the bad news is that it is always a rank of 8.

Take a look where i put it up here: // dead link removed

btw the rank of masterforums.com is 3/10.


The previous script that I had before, did calculate the rank correctly..
Moderator Remark: dead links removed
  • Pavel
  • Newbie
  • Newbie
  • Pavel
  • Posts: 11

Post 3+ Months Ago

so does anyone here know how to fix that problem ??
  • rtchar
  • Expert
  • Expert
  • User avatar
  • Posts: 606
  • Loc: Canada

Post 3+ Months Ago

Pavel

This is actually good news ...

The form is working, the script is working, PHP is working.

Now all you need to do is remove the two lines you just added at line #6 and replace them with ...

Quote:
print $_GET['url']." = ";
$pr = GetPagerank($_GET['url']);
print $pr;


Then go to the PROGRAMMING FORUM .... :lol:
  • Pavel
  • Newbie
  • Newbie
  • Pavel
  • Posts: 11

Post 3+ Months Ago

Ok i just did what you said, and this is what is looks like after line 6

Code: [ Select ]
print $_GET['url']." = ";
$pr = GetPagerank($_GET['url']);
print $pr;
function GetPagerank($urlo) {
define('GOOGLE_MAGIC', 0xE6359A60);
function xmlize($data, $WHITE=1) {
  1. print $_GET['url']." = ";
  2. $pr = GetPagerank($_GET['url']);
  3. print $pr;
  4. function GetPagerank($urlo) {
  5. define('GOOGLE_MAGIC', 0xE6359A60);
  6. function xmlize($data, $WHITE=1) {


when I use the pagerank script, i get =8

lol i really dont know why this thing is still not working... :?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 40 posts
  • Users browsing this forum: No registered users and 8 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.