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 Peon

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

    Masetek Peon

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

    frankm Peon

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #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 Peon

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #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 Peon

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

    PHP:
    1.  
    2. echo 'PageRank: '.getrank('http://www.digitalpoint.com/');
    3.  
    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:
    1.  
    2. <?php
    3. // PHP Google PageRank Calculator Script
    4. // -------------------------- April 2005
    5. // Contact author: pagerankscript@googlecommunity.com
    6.  
    7. // for updates, visit:
    8. // http://www.googlecommunity.com/scripts/google-pagerank.php
    9.  
    10. // provided by www.GoogleCommunity.com
    11. //  an unofficial community of Google fans
    12. // ---------------------------------------
    13.  
    14. // Instructions
    15. //  Upload pagerank.php to your server
    16. //   example.com is your website. yahoo.com is the website to get the PR of
    17. //  The code below displays the PR for $url
    18.  
    19. /*
    20.     This code is released unto the public domain
    21. */
    22. /*******
    23. Modified by DesignPlanet.biz
    24. *******/
    25. //header("Content-Type: text/plain; charset=utf-8");
    26. define('GOOGLE_MAGIC', 0xE6359A60);
    27.  
    28. //unsigned shift right
    29. function zeroFill($a, $b)
    30. {
    31.     $z = hexdec(80000000);
    32.         if ($z & $a)
    33.         {
    34.             $a = ($a>>1);
    35.             $a &= (~$z);
    36.             $a |= 0x40000000;
    37.             $a = ($a>>($b-1));
    38.         }
    39.         else
    40.         {
    41.             $a = ($a>>$b);
    42.         }
    43.         return $a;
    44. }
    45.  
    46. function mix($a,$b,$c) {
    47.   $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
    48.   $b -= $c; $b -= $a; $b ^= ($a<<8);
    49.   $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
    50.   $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
    51.   $b -= $c; $b -= $a; $b ^= ($a<<16);
    52.   $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
    53.   $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));  
    54.   $b -= $c; $b -= $a; $b ^= ($a<<10);
    55.   $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
    56.    
    57.   return array($a,$b,$c);
    58. }
    59.  
    60. function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
    61.     if(is_null($length)) {
    62.         $length = sizeof($url);
    63.     }
    64.     $a = $b = 0x9E3779B9;
    65.     $c = $init;
    66.     $k = 0;
    67.     $len = $length;
    68.     while($len >= 12) {
    69.         $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
    70.         $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
    71.         $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
    72.         $mix = mix($a,$b,$c);
    73.         $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
    74.         $k += 12;
    75.         $len -= 12;
    76.     }
    77.  
    78.     $c += $length;
    79.     switch($len)              /* all the case statements fall through */
    80.     {
    81.         case 11: $c+=($url[$k+10]<<24);
    82.         case 10: $c+=($url[$k+9]<<16);
    83.         case 9 : $c+=($url[$k+8]<<8);
    84.           /* the first byte of c is reserved for the length */
    85.         case 8 : $b+=($url[$k+7]<<24);
    86.         case 7 : $b+=($url[$k+6]<<16);
    87.         case 6 : $b+=($url[$k+5]<<8);
    88.         case 5 : $b+=($url[$k+4]);
    89.         case 4 : $a+=($url[$k+3]<<24);
    90.         case 3 : $a+=($url[$k+2]<<16);
    91.         case 2 : $a+=($url[$k+1]<<8);
    92.         case 1 : $a+=($url[$k+0]);
    93.          /* case 0: nothing left to add */
    94.     }
    95.     $mix = mix($a,$b,$c);
    96.     /*-------------------------------------------- report the result */
    97.     return $mix[2];
    98. }
    99.  
    100. //converts a string into an array of integers containing the numeric value of the char
    101. function strord($string) {
    102.     for($i=0;$i<strlen($string);$i++) {
    103.         $result[$i] = ord($string{$i});
    104.     }
    105.     return $result;
    106. }
    107. function getrank($url) {
    108.     $url = 'info:'.$url;
    109.     $ch = GoogleCH(strord($url));
    110.     $file = "http://www.google.com/search?client=navclient-auto&ch=6$ch&features=Rank&q=$url";
    111.     $data = file($file);
    112.     $rankarray = explode (':', $data[2]);
    113.     $rank = $rankarray[2];
    114.     return $rank;
    115. }
    116. $url = addslashes(trim($_GET['url']));
    117. if((!$url) || (empty($url))){
    118.   echo "<b>Error</b><br />You have not entered a URL to Search!";
    119.   exit();
    120. }
    121. if((eregi('%0d', $url)) || (eregi('%0a', $url))){
    122.   echo "<b>Error</b><br />Invalid Characters!";
    123. }
    124. echo '<b>'.$url.'</b> PageRank: <b>'.getrank($url).'</b><br />';
    125.  
    126. ?>
     
    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