XHanch Studio Log in | Register | Cart

Forum

[Free script] Googl...
 
Notifications
Clear all

[Free script] Google page rank (PR) checker with PHP

5 Posts
3 Users
0 Likes
1,829 Views
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

Google Page Rank (PR) Checker is a tool to check page rank of a URL of a web page of a website. FYI, every web page can have different page rank even tough the pages are on the same domain.

So, have you ever imagined to have your own dynamic Google page rank (PR) checker for your website? Now, we will expose the script to calculate page rank of a URL. 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.

Preview

Xhanch.com
Authrone.com
Google.com

Demo: http://xhanch.com/php-script-google-page-rank-pr-checker/

Quick usage

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.

<a href="" http://xhanch.com/php-script-google-page-rank-pr-checker/" ;" target="_blank" title="Google PR Checker by Xhanch Studio"><img src="" http://xhanch.com/gallery/php-script/google_pr.php" ;" alt="Google PR Checker by Xhanch Studio"></a>

Source code

Here is the complete code of this script

<?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.1rn";
            $out .= "User-Agent: $google_user_agentrn";
            $out .= "Host: $google_hostrn";
            $out .= "Connection: Closernrn";
            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);
?>

Script implementation

To use the script, please follow the steps in order to use the script:

  • Copy and paste the script into a new file
  • Save the file as PHP file such as “google_pr.php”
  • Save the file as PHP file such as “google_pr.php”
  • Upload it to your web server (ex: upload to “public_html/google_pr.php”)
  • 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
  • It should be working now.
 
Posted : 02/03/2011 11:48 pm
(@whoopii-com)
Posts: 1
New Member
 

Hi,

I don't understand at all how your script works... I should mention quickly that it's most likely me! However, I tried to copy and paste the "Quick usage" - code and can't even make that work... All I get is the message "PR N/A".

Where do you in fact input the URL?

The same question goes for the PHP script which I tried to upload, but unfortunately with the same sad result so far.

I have a feeling the code is quite promising as I tested various websites on your demo page and most of them returned a meaningful number in opposition to many other scripts found on the net intending to do the same job.

I must have misunderstood something here, can you help me out?

Thank you.

Best regards,
Claus M.

 
Posted : 27/07/2011 8:21 pm
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

Well, I'm not sure why this script does not work on your server.
I've rechecked the provides codes and those codes are exactly the same with the codes I'm currently using.

Perhaps it's just an usage issue.
What will appear if you try this?
http://[ ]your domain]/[path to your script]/google_pr.php?url=google.com

 
Posted : 30/07/2011 8:46 pm
(@therex)
Posts: 2
New Member
 

A great code! Thanks!

So alt = "" How do I print the value of the Pr1 or Pr2?

 
Posted : 06/10/2011 4:47 am
(@therex)
Posts: 2
New Member
 

Ups.
Today i seo only None. Not see Pr all site.

 
Posted : 07/10/2011 5:55 am
Share:

× Close Menu