Dynadot

Bulk PageRank and Alexa Rank Check Script

Spaceship Spaceship
Watch
Impact
83
Excuse the sloppy code and ugly design, but hey it works.

I was browsing the web and found a Google PageRank class so I decided to make this, and add Alexa support.

Install Instructions:
  1. Create a .php file and copy+paste code below into file
  2. Upload Script to server
  3. Use script.

EDIT: Big thanks to Xiberia, who fixed an issue some users were having with the script. The script with Xiberia's patch is below.
Code:

Code:
<?php
$this_script = $_SERVER['PHP_SELF'];

class GooglePageRankChecker
{
    private static $instance;
    function getRank($page)
    {
        if (!isset(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance->check($page);
    }
    function stringToNumber($string, $check, $magic)
    {
        $int32  = 4294967296;
        $length = strlen($string);
        for ($i = 0; $i < $length; $i++) {
            $check *= $magic;
            if ($check >= $int32) {
                $check = ($check - $int32 * (int) ($check / $int32));
                $check = ($check < -($int32 / 2)) ? ($check + $int32) : $check;
            }
            $check += ord($string{$i});
        }
        return $check;
    }
    
    function createHash($string)
    {
        $check1 = $this->stringToNumber($string, 0x1505, 0x21);
        $check2 = $this->stringToNumber($string, 0, 0x1003F);
        
        $factor     = 4;
        $halfFactor = $factor / 2;
        
        $check1 >>= $halfFactor;
        $check1 = (($check1 >> $factor) & 0x3FFFFC0) | ($check1 & 0x3F);
        $check1 = (($check1 >> $factor) & 0x3FFC00) | ($check1 & 0x3FF);
        $check1 = (($check1 >> $factor) & 0x3C000) | ($check1 & 0x3FFF);
        
        $calc1 = (((($check1 & 0x3C0) << $factor) | ($check1 & 0x3C)) << $halfFactor) | ($check2 & 0xF0F);
        $calc2 = (((($check1 & 0xFFFFC000) << $factor) | ($check1 & 0x3C00)) << 0xA) | ($check2 & 0xF0F0000);
        
        return ($calc1 | $calc2);
    }
    function checkHash($hashNumber)
    {
        $check = 0;
        $flag  = 0;
        
        $hashString = sprintf('%u', $hashNumber);
        $length     = strlen($hashString);
        
        for ($i = $length - 1; $i >= 0; $i--) {
            $r = $hashString{$i};
            if (1 === ($flag % 2)) {
                $r += $r;
                $r = (int) ($r / 10) + ($r % 10);
            }
            $check += $r;
            $flag++;
        }
        
        $check %= 10;
        if (0 !== $check) {
            $check = 10 - $check;
            if (1 === ($flag % 2)) {
                if (1 === ($check % 2)) {
                    $check += 9;
                }
                $check >>= 1;
            }
        }
        
        return '7' . $check . $hashString;
    }
    
    function check($page)
    {
        
        $socket = fsockopen("toolbarqueries.google.com", 80, $errno, $errstr, 30);
        
        if ($socket) {
            $out = "GET /tbr?client=navclient-auto&ch=" . $this->checkHash($this->createHash($page)) . "&features=Rank&q=info:" . $page . "&num=100&filter=0 HTTP/1.1\r\n";
            $out .= "Host: toolbarqueries.google.com\r\n";
            $out .= "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP 5.1)\r\n";
            $out .= "Connection: Close\r\n\r\n";
            fwrite($socket, $out);
            $result = "";
            while (!feof($socket)) {
                $data = fgets($socket, 128);
                $pos  = strpos($data, "Rank_");
                if ($pos !== false) {
                    $pagerank = substr($data, $pos + 9);
                    $result += $pagerank;
                }
            }
            fclose($socket);
            return $result;
        }
    }
}

function checkAlexa($domain)
{
    $result = file_get_contents("http://data.alexa.com/data?cli=10&dat=snbamz&url=http://" . $domain);
    $n      = explode("<POPULARITY URL=\"" . $domain . "/\" TEXT=\"", $result);
    @$rest = $n[1];
    $it         = explode("\"", $rest);
    $alexa_rank = $it[0];
    if (@$alexa_rank != "") {
        return $alexa_rank;
    } else {
        return "No Alexa";
    }
}

if (@$_GET["action"] == "check") {
    if (@$_GET["d"] != "") {
        $rank = GooglePageRankChecker::getRank(@$_GET["d"]);
        if ($rank != "") {
            echo $rank;
            die();
        } else {
            echo "0";
            die();
        }
    } else {
        echo "0";
        die();
    }
}

if (@$_GET["action"] == "alexa") {
    echo checkAlexa(@$_GET["d"]);
    die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>AJAX Google PageRank® and Alexa Script</title>
    <script type="text/javascript">
      function checkDomainRank(domain,id)
      {
      var xmlhttp;
      if (window.XMLHttpRequest)
        {
        xmlhttp=new XMLHttpRequest();
        }
      else
        {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      xmlhttp.onreadystatechange=function()
        {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
          {
          	document.getElementById(id).innerHTML='<font color="#FF0000"><b>'+xmlhttp.responseText+'</b></font>';
      			if(xmlhttp.responseText.indexOf("No") <= 0){
      				if(xmlhttp.responseText != "0"){
      					var cur = document.getElementById('prlist').value;
      					if(cur.indexOf('PR-'+xmlhttp.responseText+' - '+domain) <=0){
      							document.getElementById('prlist').value = cur+'PR-'+xmlhttp.responseText+' - '+domain+'\n';
      							document.getElementById(id).innerHTML='<font color="#00FF3f"><b>'+xmlhttp.responseText+'</b></font>';
						}
      				}
      			}
          }
        }
      xmlhttp.open("GET","<?php echo $this_script; ?>?action=check&d="+domain,true);
      xmlhttp.send();
      }
      
      function checkAlexaRank(domain,id)
      {
      var xmlhttp;
      if (window.XMLHttpRequest)
        {
        xmlhttp=new XMLHttpRequest();
        }
      else
        {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      xmlhttp.onreadystatechange=function()
        {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
          {
          	document.getElementById(id).innerHTML='Alexa: '+xmlhttp.responseText;
      			if(xmlhttp.responseText.indexOf("lex") <= 0){
      					var cur = document.getElementById('alexa').value;
      					if(cur.indexOf('Alexa: '+xmlhttp.responseText+' - '+domain) <=0){
      						document.getElementById('alexa').value = cur+'Alexa: '+xmlhttp.responseText+' - '+domain+'\n';
      						document.getElementById(id).innerHTML='Alexa: <font color="#FF0392"><b>'+xmlhttp.responseText+'</b></font>';
						}
      			}
          }
        }
      xmlhttp.open("GET","<?php echo $this_script; ?>?action=alexa&d="+domain,true);
      xmlhttp.send();
      }
    </script>
    <style type="text/css">
      body{
      background-color:#FFFFCC;
      }
      textarea{
      background-color:#00CCFF;
      border:1px dashed #6633FF;
      color:#000033;
      }
    </style>
  </head>
  <body>
    <center>
      <table>
        <tr>
          <td>
            <form action='<?php echo $this_script; ?>' method='post'>
              Domain List:<BR />
              <textarea style="height:300px;width:400px;" name='domains' id='domains'><?php echo @$_POST["domains"]; ?></textarea><BR />
              <input type='button' onclick="document.getElementById('domains').value='';" value='Clear List' name='clr' /> <input type='submit' value='Check Pagerank' name='subby' />
            </form>
          </td>
          <td>
            <form>
              Domains With a <b>PageRank®</b>:<BR />
              <textarea style="height:300px;width:400px;" name='prlist' id='prlist'></textarea><BR />
              <input type='reset' value='Clear List' />
            </form>
          </td>
          <td>
            <form>
              Domains with an <b>Alexa</b> Rank:<BR />
              <textarea style="height:300px;width:400px;" name='alexa' id='alexa'></textarea><BR />
              <input type='reset' value='Clear List' />
            </form>
          </td>
        </tr>
      </table>
    </center>
<?php
$jay = "";
if (@$_POST["subby"] != "") {
    if (@$_POST["domains"] != "") {
        $domains = explode("
", @$_POST["domains"]);
        
        echo "<table>";
        
        for ($i = 0; $i <= count($domains) - 1; $i++) {
            if ($domains[$i] != "") {
                echo "<tr><td>" . trim($domains[$i]) . "</td><td>Google PageRank®</td><td><span id='s" . $i . "'>" . "<span style='cursor:pointer;' onclick=\"checkDomainRank('" . trim($domains[$i]) . "','s" . $i . "');\">Loading, Click to restart.</span>" . "<script type='text/javascript'>checkDomainRank('" . trim($domains[$i]) . "','s" . $i . "');checkAlexaRank('" . trim($domains[$i]) . "','z" . $i . "');</script></span></td><td><span style='color:#039284; ' id='z" . $i . "'></span></td></tr>";
            }
        }
    }
}

echo "</table>";
?>
</body>
</html>
 
Last edited:
8
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Limitation

This is great! Do you know what is the limit or the maximum per hour/day that one can use this to check for PR?
 
0
•••
This is great! Do you know what is the limit or the maximum per hour/day that one can use this to check for PR?

I don't think there is, I've checked tens of thousands in an hour before.

Glad you like it! :)
 
0
•••
This is great! Do you know what is the limit or the maximum per hour/day that one can use this to check for PR?

toolbarqueries.google.com seems to have no query limits
the problem is it only gives you PR value but says nothing about validity

i mean when you got 1,000 domains to check there are always chances some have invalid (fake) PR so you'll need to check each further with "info:domain.tld" on google ..which is rate limited for any kind of queries including their API


*
 
0
•••
toolbarqueries.google.com seems to have no query limits
the problem is it only gives you PR value but says nothing about validity

i mean when you got 1,000 domains to check there are always chances some have invalid (fake) PR so you'll need to check each further with "info:domain.tld" on google ..which is rate limited for any kind of queries including their API


*

Yes, but if you have like a "1000" domains you can expect that only like a 10-50 would actually have the PR, so that's not that much to check your self.

I was actually doing 90,000 domains yesterday, and got like 5 that actually had PR and was available. And that's easy to check yourself.

But even that can be made into "app", maybe some bookmarklet would be possible.
 
0
•••
1
•••
great script..can be add fake pagerank check?
 
0
•••
Okay nice script but when I paste a list of domains under "Domain List" it only shows results for the last domain in the list.
This is what I am getting


yahoo.com Google PageRank® Loading, Click to restart.
google.com Google PageRank® Loading, Click to restart.
youtube.com Google PageRank® Loading, Click to restart.
dailymotion.com Google PageRank® 7 Alexa: 89

How do I fix it?
 
0
•••
great script..can be add fake pagerank check?

That is not possible, cause its the request and it only gives you back the header where is the Rank: and numbers, so there is no way to know. But If you know how, you can add the functionality by adding the Google Custom Search api into this one. But it is very limited.

By the way, this one has a limit, too. One time I tried to do like a 90,000 domains in an hour I've got blocked as "possible computer automatization" or something like that. So for those who want to use this in their scripts and classes, I would recomend the pace of like 50,000 per hour max.

By the way, you can test the Pagerank with the Alexa rank, and if the site has both, the pagerank is in 90% real.
 
1
•••
Okay nice script but when I paste a list of domains under "Domain List" it only shows results for the last domain in the list.
This is what I am getting


yahoo.com Google PageRank® Loading, Click to restart.
google.com Google PageRank® Loading, Click to restart.
youtube.com Google PageRank® Loading, Click to restart.
dailymotion.com Google PageRank® 7 Alexa: 89

How do I fix it?

Not having that problem over here, try clearing your cache and possibly cookies. If you're using Internet Explorer, simply change browsers lol.
 
0
•••
works very nicely, thanks for sharing.
 
1
•••
I had the same problem as newbie191. I checked the HTML source, and it seemed a newline after each domain name in the list was preventing the javascript/ajax from running.

For newbie191, or anyone else with the same problem, the script may be fixed by replacing this line (line 256):

Code:
echo "<tr><td>" . $domains[$i] . "</td><td>Google PageRank®</td><td><span id='s" . $i . "'>" . "<span style='cursor:pointer;' onclick=\"checkDomainRank('" . $domains[$i] . "','s" . $i . "');\">Loading, Click to restart.</span>" . "<script type='text/javascript'>checkDomainRank('" . $domains[$i] . "','s" . $i . "');checkAlexaRank('" . $domains[$i] . "','z" . $i . "');</script></span></td><td><span style='color:#039284; ' id='z" . $i . "'></span></td></tr>";

with this line:

Code:
echo "<tr><td>" . trim($domains[$i]) . "</td><td>Google PageRank®</td><td><span id='s" . $i . "'>" . "<span style='cursor:pointer;' onclick=\"checkDomainRank('" . trim($domains[$i]) . "','s" . $i . "');\">Loading, Click to restart.</span>" . "<script type='text/javascript'>checkDomainRank('" . trim($domains[$i]) . "','s" . $i . "');checkAlexaRank('" . trim($domains[$i]) . "','z" . $i . "');</script></span></td><td><span style='color:#039284; ' id='z" . $i . "'></span></td></tr>";

Which removes the newlines and/or other whitespace from the domains in a domain list. Hope that helps. Not sure why it works for most people, but not others.

As others have said, this is a great script. Thanks, DomainIdiot.
 
3
•••
I had the same problem as newbie191. I checked the HTML source, and it seemed a newline after each domain name in the list was preventing the javascript/ajax from running.

For newbie191, or anyone else with the same problem, the script may be fixed by replacing this line (line 256):

Code:
echo "<tr><td>" . $domains[$i] . "</td><td>Google PageRank®</td><td><span id='s" . $i . "'>" . "<span style='cursor:pointer;' onclick=\"checkDomainRank('" . $domains[$i] . "','s" . $i . "');\">Loading, Click to restart.</span>" . "<script type='text/javascript'>checkDomainRank('" . $domains[$i] . "','s" . $i . "');checkAlexaRank('" . $domains[$i] . "','z" . $i . "');</script></span></td><td><span style='color:#039284; ' id='z" . $i . "'></span></td></tr>";

with this line:

Code:
echo "<tr><td>" . trim($domains[$i]) . "</td><td>Google PageRank®</td><td><span id='s" . $i . "'>" . "<span style='cursor:pointer;' onclick=\"checkDomainRank('" . trim($domains[$i]) . "','s" . $i . "');\">Loading, Click to restart.</span>" . "<script type='text/javascript'>checkDomainRank('" . trim($domains[$i]) . "','s" . $i . "');checkAlexaRank('" . trim($domains[$i]) . "','z" . $i . "');</script></span></td><td><span style='color:#039284; ' id='z" . $i . "'></span></td></tr>";

Which removes the newlines and/or other whitespace from the domains in a domain list. Hope that helps. Not sure why it works for most people, but not others.

As others have said, this is a great script. Thanks, DomainIdiot.

Was having the same problem. Your fix solved it. Thanks
 
0
•••
Thank you so much for the code.

I have a problem. My pagerank checker which use some of this script: seoinfo.no/pagerank/index.php
In order to get the tablesorter to work i need my output to be in HTML. Now my output is like this:

HTML:
 <tr>					
<td>vg.no</td>
<td style='color:#FF0000' id='s0'><span style='cursor:pointer;' onclick="checkDomainRank('vg.no','s0');">Loading, Klikk for å restarte.</span><script type='text/javascript'>checkDomainRank('vg.no','s0');checkAlexaRank('vg.no','z0');
				
</script></td><td><span style='color:#039284; ' id='z0'></span></td></tr><tr>					
<td>ap.no</td>
<td style='color:#FF0000' id='s1'><span style='cursor:pointer;' onclick="checkDomainRank('ap.no','s1');">Loading, Klikk for å restarte.</span><script type='text/javascript'>checkDomainRank('ap.no','s1');checkAlexaRank('ap.no','z1');
				
</script></td><td><span style='color:#039284; ' id='z1'></span></td></tr>

Which is not readable for the tablesorter.js

How can i get the output to be readable for the tablesorter?
Like:
<tr>
<td><span style="color:#f50;">PR 5</span></td>
<td><span style="color:#00a">Alexa: N/A</span></td>
</tr>
 
0
•••
1
•••
Thank you so much for the code.

I have a problem. My pagerank checker which use some of this script: seoinfo.no/pagerank/index.php
In order to get the tablesorter to work i need my output to be in HTML. Now my output is like this:

HTML:
 <tr>					
<td>vg.no</td>
<td style='color:#FF0000' id='s0'><span style='cursor:pointer;' onclick="checkDomainRank('vg.no','s0');">Loading, Klikk for å restarte.</span><script type='text/javascript'>checkDomainRank('vg.no','s0');checkAlexaRank('vg.no','z0');
				
</script></td><td><span style='color:#039284; ' id='z0'></span></td></tr><tr>					
<td>ap.no</td>
<td style='color:#FF0000' id='s1'><span style='cursor:pointer;' onclick="checkDomainRank('ap.no','s1');">Loading, Klikk for å restarte.</span><script type='text/javascript'>checkDomainRank('ap.no','s1');checkAlexaRank('ap.no','z1');
				
</script></td><td><span style='color:#039284; ' id='z1'></span></td></tr>

Which is not readable for the tablesorter.js

How can i get the output to be readable for the tablesorter?
Like:
<tr>
<td><span style="color:#f50;">PR 5</span></td>
<td><span style="color:#00a">Alexa: N/A</span></td>
</tr>

You have to update tablesorter every time it is dynamically changed. This is done by calling "update" through your tablesorter element.

In your case, it'd be:
Code:
$(".tablesorter").trigger("update");

I haven't tested this, but you could try changing (in the checkAlexaRank function):
Code:
if(cur.indexOf('Alexa: '+xmlhttp.responseText+' - '+domain) <=0){
      						document.getElementById('alexa').value = cur+'Alexa: '+xmlhttp.responseText+' - '+domain+'\n';
      						document.getElementById(id).innerHTML='Alexa: <font color="#FF0392"><b>'+xmlhttp.responseText+'</b></font>';
						}

To:
Code:
if(cur.indexOf('Alexa: '+xmlhttp.responseText+' - '+domain) <=0){
      						document.getElementById('alexa').value = cur+'Alexa: '+xmlhttp.responseText+' - '+domain+'\n';
      						document.getElementById(id).innerHTML='Alexa: <font color="#FF0392"><b>'+xmlhttp.responseText+'</b></font>';
							$(".tablesorter").trigger("update");
						}
 
0
•••
#DomainIdiot thank you for trying to help me, really appreciate it :)

I believe that's not the problem. tablesorter can't understand the HTML output from the script.
The output is javascript inside the <td></td>. Not normal numbers/letters.
The script do not have anything to sort because of the output is not known for the script. I need a output that is in normal numbers/letters. not like:

HTML:
<td style='color:#FF0000' id='s0'>
<span style='cursor:pointer;' onclick="checkDomainRank('vg.no','s0');">
Loading, Klikk for å restarte.</span>
<script type='text/javascript'>checkDomainRank('vg.no','s0');checkAlexaRank('vg.no','z0');
</script>

The result have to be like this i gues.
HTML:
<td id="s3" style="color:#FF0000">
<b>N/A</b>
</td>
<td>
<span id="z3" style="color:#039284; ">Alexa: 12450917</span>
</td>
 
0
•••
Go into the code and CTRL+F / Find "Alexa: " and remove that.

Then, in the function that updates the table, after you're done updating the table to say the Alexa, call the function
Code:
$(".tablesorter").trigger("update");

I tested it after the page has been rendered and worked fine, but haven't tested it when the page has not been rendered yet.

#DomainIdiot thank you for trying to help me, really appreciate it :)

I believe that's not the problem. tablesorter can't understand the HTML output from the script.
The output is javascript inside the <td></td>. Not normal numbers/letters.
The script do not have anything to sort because of the output is not known for the script. I need a output that is in normal numbers/letters. not like:

HTML:
<td style='color:#FF0000' id='s0'>
<span style='cursor:pointer;' onclick="checkDomainRank('vg.no','s0');">
Loading, Klikk for å restarte.</span>
<script type='text/javascript'>checkDomainRank('vg.no','s0');checkAlexaRank('vg.no','z0');
</script>

The result have to be like this i gues.
HTML:
<td id="s3" style="color:#FF0000">
<b>N/A</b>
</td>
<td>
<span id="z3" style="color:#039284; ">Alexa: 12450917</span>
</td>
 
0
•••
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back