pagerank button image -- how?

Discussion in 'PHP' started by fsmedia, May 13, 2006.

  1. #1
    How does the pagerank image work so all you have to do is put an image on your site and the pagerank is displayed? Can someone point out an article or script that does it? Thanks!
     
    fsmedia, May 13, 2006 IP
  2. Shoemoney

    Shoemoney $

    Messages:
    4,474
    Likes Received:
    588
    Best Answers:
    0
    Trophy Points:
    295
    #2
    the image is actual php code that just sends a image header with the pagerank drawn
     
    Shoemoney, May 13, 2006 IP
  3. fsmedia

    fsmedia Prominent Member

    Messages:
    5,163
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    390
    #3
    Do you have an example of the code that I Could use?
     
    fsmedia, May 13, 2006 IP
  4. Shoemoney

    Shoemoney $

    Messages:
    4,474
    Likes Received:
    588
    Best Answers:
    0
    Trophy Points:
    295
    #4
    the main thing is getting the code then just draw it useing the gdlib

    http://us3.php.net/gd

    I am pretty busy today but I will try to come up with something
     
    Shoemoney, May 13, 2006 IP
  5. fsmedia

    fsmedia Prominent Member

    Messages:
    5,163
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    390
    #5
    Oh ok, thanks! I'll keep an eye out for something or try to research some more on the web.
     
    fsmedia, May 13, 2006 IP
  6. BILZ

    BILZ Peon

    Messages:
    1,515
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    0
    #6
    BILZ, May 13, 2006 IP
  7. Shoemoney

    Shoemoney $

    Messages:
    4,474
    Likes Received:
    588
    Best Answers:
    0
    Trophy Points:
    295
    #7
    Shoemoney, May 13, 2006 IP
  8. fsmedia

    fsmedia Prominent Member

    Messages:
    5,163
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    390
    #8
    Yes Shoemoney, I am looking for the PHP code -- I want to self-host it...
     
    fsmedia, May 13, 2006 IP
  9. artViper

    artViper Peon

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    <?php 
    session_start();
    $url = $_SESSION['url'];
    
    
    
    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;
    }
    
    define('GOOGLE_MAGIC',0xE6359A60);
    
    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){
        case 11:$c+=($url[$k+10]<<24);
        case 10:$c+=($url[$k+9]<<16);
        case 9:$c+=($url[$k+8]<<8);
        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]);
      }
      $mix=Mix($a,$b,$c);
      return $mix[2];
    }
    
    function StringOrder($string){
      for($i=0;$i<strlen($string);$i++){$result[$i]=ord($string{$i});}
      return $result;
    }
    
    $target=trim($_GET['uri']);    
    
    if($target!=""){
      $server="www.google.com";
      
      /* Alternative Server
      $server="toolbarqueries.google.com";
      $server="64.233.161.99";
      $server="64.233.161.104";
      $server="66.102.7.99";
      $server="66.102.7.104";
      $server="216.239.59.99";
      $server="216.239.59.104";
      $server="216.239.37.104";
      $server="216.239.39.99";
      $server="216.239.39.104";
      $server="66.102.11.99";
      $server="66.102.11.104";
      $server="216.239.57.99";
      $server="216.239.57.104";
      $server="66.102.9.99";
      $server="66.102.9.104";
      $server="216.239.53.99";
      $server="216.239.53.104";
      */
      
      $url="info:"."$target";
      $ch=trim(str_replace("-","",sprintf("6%u\n",GoogleCH(StringOrder($url)))));
      $res="http://$server/search?client=navclient-auto&ch=$ch&features=Rank&q=$url";
      $data=@fopen("$res",r);
      if($data){
        while($line = fgets($data,1024)) {
          if(substr($line,0,7)=="Rank_1:"){$rankline = $line;}
        }
        fclose($data);
        $pagerank = trim(substr($rankline,9,2));
        if($pagerank==""){$pagerank="0";}
    						
    						$img;
    						switch($pagerank){
    							case 0:	$img = "img/gpr0.gif"; break;
    							case 1:	$img = "img/gpr1.gif"; break;
    							case 2: $img	= "img/gpr2.gif"; break;
    							case 3: $img	= "img/gpr3.gif"; break;
    							case 4: $img	= "img/gpr4.gif"; break;
    							case 5: $img	= "img/gpr5.gif"; break;
    							case 6: $img	= "img/gpr6.gif"; break;
    							case 7: $img	= "img/gpr7.gif"; break;
    							case 8: $img	= "img/gpr8.gif"; break;
    							case 9: $img	= "img/gpr9.gif"; break;
    							case 10: $img	= "img/gpr10.gif"; break;
    							}
    						
    								
    								
    								$_POST['pr'] = $pagerank;
    								header("Content: image/gif");
    								header("Location: $img");
    								
    						
      }
    }
    
    ?>
    PHP:
    There you go...
     
    artViper, May 13, 2006 IP
    fsmedia likes this.
  10. Shoemoney

    Shoemoney $

    Messages:
    4,474
    Likes Received:
    588
    Best Answers:
    0
    Trophy Points:
    295
    #10
    very nice man: fsmedia you will probably want to cache the image if you do some high volume...
     
    Shoemoney, May 13, 2006 IP
    fsmedia likes this.
  11. fsmedia

    fsmedia Prominent Member

    Messages:
    5,163
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    390
    #11
    Thanks Shoemoney and artViper! I won't be doing high volumes at the current time, it's only for personal testing right now, but I'll get into high volumes later on with a new site I'm launching. Just starting to do testing for smaller sites right now of our products.
     
    fsmedia, May 13, 2006 IP
  12. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I find that PHP code very useful.... Thanks!
     
    ajscottsr, May 13, 2006 IP
  13. netaddict

    netaddict Peon

    Messages:
    640
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Are you guys sure Google has no problem by the usage of such scripts?
     
    netaddict, May 14, 2006 IP
  14. [*-AnOnYmOuS-*]

    [*-AnOnYmOuS-*] Active Member

    Messages:
    253
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #14
    Personally, I took off the PHPLDs code for PR and I'm using it :D . Uh.. creativity strikes me.. :p .
     
    [*-AnOnYmOuS-*], Aug 21, 2006 IP