- 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:
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:
I was browsing the web and found a Google PageRank class so I decided to make this, and add Alexa support.
Install Instructions:
- Create a .php file and copy+paste code below into file
- Upload Script to server
- 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: