1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PR checker script

Discussion in 'PHP' started by Masetek, Nov 25, 2005.

  1. #1
    Hey,

    I have been downloading the various php pagerank checking scripts and not 1 of them has worked when I've uploaded it (they all work on the demos). I am basically after a function that I can pass a url to which finds pagerank. Does anyone have an uptodate script that's working that I can try?

    Thanks
     
    Masetek, Nov 25, 2005 IP
  2. execute

    execute Peon

    Messages:
    301
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you need to use the Google API at api.google.com but I really don't understand how it works, they have java and CGI examples i think but i have no idea of how they work, because they use some sort of SOAP and things i dunno.

    Maybe someone can explain how it works, or how to send queries to google using api google? How to SOAP thing works? That might give me a way to design one for you ;O
     
    execute, Nov 25, 2005 IP
  3. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
  4. Masetek

    Masetek Peon

    Messages:
    820
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Masetek, Nov 25, 2005 IP
  5. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #5
    Yeah , I think you made an error somewhere. it is still working for me..
     
    frankm, Nov 25, 2005 IP
  6. Masetek

    Masetek Peon

    Messages:
    820
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I thought the url in the file might have been wrong, since google is returning a 403
     
    Masetek, Nov 25, 2005 IP
  7. mitchandre

    mitchandre Peon

    Messages:
    313
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #7
    mitchandre, Nov 25, 2005 IP
  8. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #8
    yup, that looks familiar.
     
    frankm, Nov 25, 2005 IP
  9. Masetek

    Masetek Peon

    Messages:
    820
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Yep, that's the exact code. I just cut that an pasted it into ultraedit. I didn't change anything. I email the guy who wrote it to see what he thinks about the error.
     
    Masetek, Nov 25, 2005 IP
  10. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #10
    I just copied and pasted the same code to 'test.php' and replace the last line of code
    
    echo 'PageRank: '.getrank($_REQUEST["url"]).'<br /><small>provided by <a href="http://www.googlecommunity.com/" target="_blank">Google Community.com</a></small>'; 
    
    PHP:
    with

    
    echo 'PageRank: '.getrank('http://www.digitalpoint.com/');
    
    PHP:
    and it returns:
    PageRank: 7

    so the code is working for me...
     
    frankm, Nov 25, 2005 IP
  11. Masetek

    Masetek Peon

    Messages:
    820
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Hrm...this is strange. I still get the same error. Would it be possible for you to email me a copy of your code?
     
    Masetek, Nov 25, 2005 IP
  12. sufyaaan

    sufyaaan Banned

    Messages:
    218
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #12
    This script is working for me. Well, AFAIK it requests PR data from G data center - just like your G toolbar does.

    So, if you are using this script from behind a proxy server, it might be unable to open stream and fails. Try using it without any proxy and it will definitely work for you, too.
     
    sufyaaan, Nov 25, 2005 IP
  13. Masetek

    Masetek Peon

    Messages:
    820
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I'm running the script from my web server, theres no proxy :) I will try to run it from an alternative server and see how I go
     
    Masetek, Nov 26, 2005 IP
  14. execute

    execute Peon

    Messages:
    301
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #14
    works fine for me too, i built a tool for it in my website.
     
    execute, Nov 26, 2005 IP
  15. execute

    execute Peon

    Messages:
    301
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I have modified the script to make it more safe (against hacking etc, just incase). And to get rid of the errors you guys are having:
    
    <?php
    // PHP Google PageRank Calculator Script
    // -------------------------- April 2005
    // Contact author: pagerankscript@googlecommunity.com
    
    // for updates, visit:
    // http://www.googlecommunity.com/scripts/google-pagerank.php
    
    // provided by www.GoogleCommunity.com
    //  an unofficial community of Google fans
    // ---------------------------------------
    
    // Instructions
    //  Upload pagerank.php to your server
    //   example.com is your website. yahoo.com is the website to get the PR of
    //  The code below displays the PR for $url
    
    /*
        This code is released unto the public domain
    */
    /*******
    Modified by DesignPlanet.biz
    *******/
    //header("Content-Type: text/plain; charset=utf-8");
    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;
    }
    function getrank($url) {
        $url = 'info:'.$url;
        $ch = GoogleCH(strord($url));
        $file = "http://www.google.com/search?client=navclient-auto&ch=6$ch&features=Rank&q=$url";
        $data = file($file);
        $rankarray = explode (':', $data[2]);
        $rank = $rankarray[2];
        return $rank;
    }
    $url = addslashes(trim($_GET['url']));
    if((!$url) || (empty($url))){
      echo "<b>Error</b><br />You have not entered a URL to Search!";
      exit();
    }
    if((eregi('%0d', $url)) || (eregi('%0a', $url))){
      echo "<b>Error</b><br />Invalid Characters!";
    }
    echo '<b>'.$url.'</b> PageRank: <b>'.getrank($url).'</b><br />';
    
    ?>
    PHP:
     
    execute, Nov 26, 2005 IP
  16. Masetek

    Masetek Peon

    Messages:
    820
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Same error :mad:

    I'm thinking this has something to do with google not allowing me to access their datacenter from my server...hence the forbidden error.
     
    Masetek, Nov 26, 2005 IP
  17. Masetek

    Masetek Peon

    Messages:
    820
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #17
    I just tried this exact script on a free php hosting site, and same error. Does anyone have (or know of) a completely different script I can try?
     
    Masetek, Nov 26, 2005 IP
  18. hdpinn

    hdpinn Peon

    Messages:
    48
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Works for me too, I've tried it at least on 2 servers. If one thing is a little off in the url you send google, you'll get the forbidden error. Can't be done with API.
     
    hdpinn, Nov 26, 2005 IP
  19. execute

    execute Peon

    Messages:
    301
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #19
    i hope you are doing something like
    http://example.com/PRscript.php?url=http://www.designplanet.biz
    or in that syntax, or you might get an error. But no you Should NOT get an error, you MUST be doing something wrong.

    Can you copy and paste the exact code, (without the PHP tags) into here... Maybe you copied it wrong or added something accidently.
     
    execute, Nov 26, 2005 IP
  20. Masetek

    Masetek Peon

    Messages:
    820
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #20
    I copied your code from a few posts ago. Here it is:

    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;

    }

    function getrank($url) {

    $url = 'info:'.$url;

    $ch = GoogleCH(strord($url));

    $file = "http://www.google.com/search?client=navclient-auto&ch=6$ch&features=Rank&q=$url";

    $data = file($file);

    $rankarray = explode (':', $data[2]);

    $rank = $rankarray[2];

    return $rank;

    }

    $url = addslashes(trim($_GET['url']));

    if((!$url) || (empty($url))){

    echo "<b>Error</b><br />You have not entered a URL to Search!";

    exit();

    }

    if((eregi('%0d', $url)) || (eregi('%0a', $url))){

    echo "<b>Error</b><br />Invalid Characters!";

    }

    echo '<b>'.$url.'</b> PageRank: <b>'.getrank($url).'</b><br />';
     
    Masetek, Nov 26, 2005 IP