• Xhanch - WP Manga - Have your own automated manga reader website

PHP Script – Google Page Rank (PR) Checker

Have you ever imagined to have your own dynamic Google page rank (PR) checker for your website? Now, we will expose the script to you for free. With this, you will not need to use similar services provided by third-party. The script is written in PHP and it is working fine and accurately. So, what you need to do is just copy this script into a PHP file and save it and upload it to your web server and it is ready to use.

If you don’t care about the script and just want to use this service, you just need to copy and paste the following code into your web page code.

Google PR Checker by Xhanch Studio

Demo

Type your page URL:



(Press enter if you have finished typing your URL and wait for a moment)


Here’s the result:

Page Rank

Source Code

<?php
    //By    : Xhanch Studio
    //URL   : http://xhanch.com/

    //convert a string to a 32-bit integer
    function str_to_num($str,$check,$magic){
        $int32_unit = 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
            if($check >= $int32_unit) {
                $check -= $int32_unit * (int)($check/$int32_unit);
                //if the check less than -2^31
                if($check < -2147483648)
                    $check += $int32_unit;
            }
            $check += ord($str{$i});
        }
        return $check;
    }

    //generate a hash for a url
    function hash_url($str){
        $check1 = str_to_num($str, 0x1505, 0x21);
        $check2 = str_to_num($str, 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);
    }

    //generate a check sum for the hash string
    function check_hash($hash_num){
        $check_byte = 0;
        $flag = 0;
        $hash_str = sprintf('%u', $hash_num) ;
        $length = strlen($hash_str);
        for($i=($length-1);$i>=0;$i--){
            $re = $hash_str{$i};
            if(1 === ($flag % 2)){
                $re += $re;
                $re = (int)($re / 10) + ($re % 10);
            }
            $check_byte += $re;
            $flag++;
        }
        $check_byte %= 10;
        if(0 !== $check_byte){
            $check_byte = 10 - $check_byte;
            if(1 === ($flag % 2)){
                if(1 === ($check_byte % 2))
                    $check_byte += 9;
                $check_byte >>= 1;
            }
        }
        return '7'.$check_byte.$hash_str;
    }

    //return the check sum hash
    function get_check_sum($url){
        return check_hash(hash_url($url));
    }

    //return the pr for the specified url
    function get_pr($url){
        $google_host = 'toolbarqueries.google.com';
        $google_user_agent = 'Mozilla/5.0 (Windows; U; ';
        $google_user_agent .= 'Windows NT 5.1; en-US; rv:1.8.0.6) ';
        $google_user_agent .= 'Gecko/20060728 Firefox/1.5';

        $ch = get_check_sum($url);
        $fp = fsockopen($google_host, 80, $errno, $errstr, 30);
        if ($fp){
            $out = "GET /search?client=navclient-auto&ch=$ch";
            $out .= "&features=Rank&q=info:$url HTTP/1.1\r\n";
            $out .= "User-Agent: $google_user_agent\r\n";
            $out .= "Host: $google_host\r\n";
            $out .= "Connection: Close\r\n\r\n";
            fwrite($fp, $out);
            while (!feof($fp)) {
                $data = fgets($fp, 128);
                //echo $data;
                $pos = strpos($data, "Rank_");
                if($pos === false){
                }else{
                    $pr = substr($data, $pos + 9);
                    $pr = trim($pr);
                    $pr = str_replace("\n",'',$pr);
                    return $pr;
                }
            }
            fclose($fp);
        }
    }

    //generating image
    //In this script, we are about to create a 80px x 15px image
    $url = '';
    if(isset($_GET['url'])){
        $url = urldecode($_GET['url']);
        if(!preg_match('/^(http:\/\/)?([^\/]+)/i', $url))
        $url = 'http://'.$url;
    }else
        $url = $_SERVER['HTTP_REFERER'];

    $pr = get_pr($url);

    $img = imagecreatetruecolor(80,15);

    $clr_red = imagecolorallocate($img,255,0,0);
    $clr_white = imagecolorallocate($img,255,255,255);
    $clr_green = imagecolorallocate($img,0,255,0);
    $clr_blue = imagecolorallocate($img,0,0,255);

    $is_na = false;
    if((string)$pr == ''){
        $pr = 'N/A';
        $is_na = true;
    }
    imagefill($img,0,0,$clr_white);
    imagerectangle($img,0,0,79,14,$clr_blue);
    imagestring($img,2,4,1,'PR '.$pr,$clr_blue);

    if(!$is_na){
        for($i=0;$i<$pr;$i++){
            if($i<5){
                $x = ($i*9)+37;
                $y = 4;
            }else{
                $x = (($i-5)*9)+37;
                $y = 10;
            }
            imagefilledellipse($img,$x,$y,5,5,$clr_red);
        }
    }

    header('Content-type: image/jpeg');
    imagejpeg($img);
    imagedestroy($img);
?>

How To Use The Script

Please follow the steps in order to use the script:

  1. Copy and paste the script into a new file
  2. Save the file as PHP file such as “google_pr.php”
  3. Upload it to your web server (ex: upload to “public_html/google_pr.php”)
  4. Put this HTML code into your web page
    <img src=”your_url.com/google_pr.php” style=”border-width:1px;border-color:blue;border-style:solid”>
    Make sure the src is set to the location of where you have uploaded the google PR script
  5. It should be working now.

Click here to support our work. Thanks :)


4 Responses to “PHP Script – Google Page Rank (PR) Checker”

  1. ricky rdX says:

    thanks for sharing..
    Very easy guide

  2. tikus says:

    nice coding, need that script
    thx

  3. Excellent, nice share.. Thanks for this i was about to purchase this kind of scripts until i saw this posted on DP.

    Cheers

  4. Awesome! This is the best PHP PR checker script out there from what I could find!

    Thanks!

Leave a Reply

  • NOTICE

    Xhanch Studio is finally online after successfully moved from shared hosting to our own VPS Hosting.

    Please note that our primary email admin@xhanch.com is not functioning yet. So, please send your emails to xhanch@gmail.com for the moment until we resolve this issue.

    Regards, Xhanch Studio
  • Sponsored Ads

    WalkNote.com - A Place to Share, Have Fun and Get Connected Place you ad here
  • PayPal Verified

    Happy with our free services? You may donate us. Thanks!

    Donate
  • Latest Tweets

    Here are our recent tweets:

    • @xhanch Your a legend!!! I have just used the first part of the code so the links are a different colour and it looks fab, Thanks! - posted on 3 days ago via Tweetie for Mac

    • Xhanch - My Twitter 2.0.2 is released. Some minor fixings - posted on 3 days ago via web

    • We have finished the website migration to a VPS server - posted on 3 days ago via web

    • @Bunglenick put this code to custom CSS: {xmt_id}.xmt ul li.tweet_list{color:#ffffff} {xmt_id}.xmt ul li.tweet_list a{color:#ffffff} - posted on 3 days ago via web

    • @xhanch Hi there, how do I go about changing the colour of the text in your twitter app? Its black but I need white. - posted on 5 days ago via Tweetie for Mac