Basic Script to make Web Diagnostic Tool
Hereunder you can find basic php script to run Web Diagnostic. This is a base script before i make some modification including css and html.
This script can check Google pagerank, Technorati, Alexa, indexed/backlink, Googlebot last access and DMOZ listing.
At the end of this article, you can download this script as well. Appreciate if you could donate through paypal icon located on the left screen or give a link on your site to diagnosticoweb.com .
Hereunder are all functions i use on the script (on yellow color). To see php codes, just click on it one by one to expand (or shrink):
Global Variable
$alexa_backlink=0;
$alexa_reach=0;
$techno_inblogs=0;
$techno_inlinks=0;
$techno_update='';
Google Page Rank
function StrToNum($Str, $Check, $Magic)
{
$Int32Unit = 4294967296; // 2^32
$length = strlen($Str);
for ($i = 0; $i < $length; $i++) {
$Check *= $Magic;
if ($Check >= $Int32Unit) {
$Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
$Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
}
$Check += ord($Str{$i});
}
return $Check;
}
/*
* Generate a hash for a url
*/
function HashURL($String)
{
$Check1 = StrToNum($String, 0x1505, 0x21);
$Check2 = StrToNum($String, 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 checksum for the hash string
*/
function CheckHash($Hashnum)
{
$CheckByte = 0;
$Flag = 0;
$HashStr = sprintf('%u', $Hashnum) ;
$length = strlen($HashStr);
for ($i = $length - 1; $i >= 0; $i --) {
$Re = $HashStr{$i};
if (1 === ($Flag % 2)) {
$Re += $Re;
$Re = (int)($Re / 10) + ($Re % 10);
}
$CheckByte += $Re;
$Flag ++;
}
$CheckByte %= 10;
if (0 !== $CheckByte) {
$CheckByte = 10 - $CheckByte;
if (1 === ($Flag % 2) ) {
if (1 === ($CheckByte % 2)) {
$CheckByte += 9;
}
$CheckByte >>= 1;
}
}
return '7'.$CheckByte.$HashStr;
}
function getpagerank($url) {
$query="http://toolbarqueries.google.com/search?client=navclient-auto&ch=".CheckHash(HashURL($url)). "&features=Rank&q=info:".$url."&num=100&filter=0";
$data=file_get_contents_curl($query);
$pos = strpos($data, "Rank_");
if($pos === false){} else{
$pagerank = substr($data, $pos + 9);
return $pagerank;
}
}
Technorati Rank
function get_technorati_rank($url, $apikey)
{
global $techno_url, $techno_inblogs, $techno_inlinks, $techno_update;
$technorati_xml = "http://api.technorati.com/bloginfo?key=" . $apikey . "&url=" . $url;
$xml_parser = xml_parser_create();
/*
$fp = fopen($technorati_xml, "r") or die("Error: Reading XML data.");
$data = "";
while (!feof($fp)) {
$data .= fread($fp, 8192);
}
fclose($fp);
*/
$data=file_get_contents_curl($technorati_xml);
xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);
$index_rank = $index['RANK'][0];
$techno_rank = $vals[$index_rank]['value'];
$index_inblogs = $index['INBOUNDBLOGS'][0];
$techno_inblogs = number_format(trim($vals[$index_inblogs]['value']));
$index_inlinks = $index['INBOUNDLINKS'][0];
$techno_inlinks = number_format(trim($vals[$index_inlinks]['value']));
$index_update = $index['LASTUPDATE'][0];
$techno_update = trim($vals[$index_update]['value']);
return $techno_rank;
}
Alexa Rank and Popularity
function get_alexa_popularity($url)
{
global $alexa_backlink, $alexa_reach;
$alexaxml = "http://xml.alexa.com/data?cli=10&dat=nsa&url=".$url;
$xml_parser = xml_parser_create();
/*
$fp = fopen($alexaxml, "r") or die("Error: Reading XML data.");
$data = "";
while (!feof($fp)) {
$data .= fread($fp, 8192);
}
fclose($fp);
*/
$data=file_get_contents_curl($alexaxml);
xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);
$index_popularity = $index['POPULARITY'][0];
$index_reach = $index['REACH'][0];
$index_linksin = $index['LINKSIN'][0];
$alexarank = $vals[$index_popularity]['attributes']['TEXT'];
$alexa_backlink = $vals[$index_linksin]['attributes']['NUM'];
$alexa_reach = $vals[$index_reach]['attributes']['RANK'];
return $alexarank;
}
function alexa_backlink($url)
{
global $alexa_backlink;
if ($alexa_backlink!=0)
{
return $alexa_backlink;
} else {
$rank=get_alexa_popularity($url);
return $alexa_backlink;
}
}
function alexa_reach_rank($url)
{
global $alexa_reach;
if ($alexa_reach!=0)
{
return $alexa_reach;
} else {
$rank=get_alexa_popularity($url);
return $alexa_reach;
}
}
Google BackLink
function google_backlink($uri)
{
$uri = trim(eregi_replace('http://', '', $uri)); $uri = trim(eregi_replace('http', '', $uri));
$url = 'http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=link:'.$uri.'&filter=0';
$v = file_get_contents_curl($url);
preg_match('/of about \(.*?)\<\/b\>/si',$v,$r);
preg_match('/of \(.*?)\<\/b\>/si',$v,$s);
if ($s[1]!=0) {
return $s[1];
} else {
return ($r[1]) ? $r[1] : '0';
}
}
Yahoo Backlink
function yahoo_inlink($uri)
{
$uri = trim(eregi_replace('http://', '', $uri)); $uri = trim(eregi_replace('http', '', $uri));
$url = 'http://siteexplorer.search.yahoo.com/advsearch?p=http://'.$uri.'&bwm=i&bwmf=s&bwmo=&fr2=seo-rd-se';
$v = file_get_contents_curl($url);
preg_match('/of about \(.*?) \<\/strong\>/si',$v,$r);
return ($r[1]) ? $r[1] : '0';
}
Altavista Backlink
function altavista_link($sURL)
{
$url="http://www.altavista.com/web/results?itag=ody&q=link%3A$sURL&kgs=0&kls=0";
$data = file_get_contents_curl($url);
$spl=explode("AltaVista found ",$data);
$spl2=explode(" results",$spl[1]);
$ret=trim($spl2[0]);
if(strlen($ret)==0)
{
return(0);
}
else
{
return($ret);
}
}
AllTheWeb Backlink
function alltheweb_link($sURL)
{
$url="http://www.alltheweb.com/search?cat=web&cs=utf-8&q=link%3A".urlencode($sURL)."&_sb_lang=any";
$data = file_get_contents_curl($url);
$spl=explode(" of ",$data);
$spl2=explode(" ",$spl[1]);
$ret=trim($spl2[0]);
if(strlen($ret)==0)
{
return(0);
}
else
{
return($ret);
}
}
Google Indexed
function google_indexed($uri)
{
$uri = trim(eregi_replace('http://', '', $uri)); $uri = trim(eregi_replace('http', '', $uri));
$url = 'http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=site:'.$uri.'&filter=0';
$v = file_get_contents_curl($url);
preg_match('/of about \(.*?)\<\/b\>/si',$v,$r);
preg_match('/of \(.*?)\<\/b\>/si',$v,$s);
if ($s[1]!=0) {
return $s[1];
} else {
return ($r[1]) ? $r[1] : '0';
}
}
Yahoo Indexed
function yahoo_indexed($uri)
{
$uri = trim(eregi_replace('http://', '', $uri)); $uri = trim(eregi_replace('http', '', $uri));
$url = 'http://siteexplorer.search.yahoo.com/advsearch?p=http://'.$uri.'&bwm=p&bwmf=s&bwmo=d';
$v = file_get_contents_curl($url);
preg_match('/of about \(.*?) \<\/strong\>/si',$v,$r);
return ($r[1]) ? $r[1] : '0';
}
MSN Live Indexed
function msn_indexed($uri)
{
$uri = trim(eregi_replace('http://', '', $uri)); $uri = trim(eregi_replace('http', '', $uri));
$url = 'http://search.msn.com/results.aspx?q=site:'.$uri;
$data = file_get_contents_curl($url);
$spl=explode("of",$data);
$spl2=explode("results",$spl[1]);
$ret=trim($spl2[0]);
if(strlen($ret)==0)
{
return(0);
}
else
{
return($ret);
}
}
GoogleBot Last Access
function googlebot_lastaccess($url)
{
$url = 'http://209.85.175.104/search?hl=en&q=cache:'.$url.'&btnG=Google+Search&meta=';
$data = file_get_contents_curl($url);
$spl=explode("as retrieved on",$data);
$spl2=explode(". ",$spl[1]);
$ret=trim($spl2[0]);
if(strlen($ret)==0)
{
return(0);
}
else
{
return($ret);
}
}
POST request with cURL
function do_post_request_curl($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // add POST fields
$result = curl_exec($ch); // run the whole process
curl_close($ch);
return $result;
}
DMOZ Listed?
function dmoz_listed($url)
{
$url = trim(eregi_replace('http://', '', $url));
$url = trim(eregi_replace('http', '', $url));
$dmozurl='http://search.dmoz.org/cgi-bin/search?search='.$url;
$data = file_get_contents_curl($dmozurl);
$pos=strpos($data, 'match');
if ($pos==0) {
return 0;
} else {
return 1;
}
}
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
You can paste all the above code into a file like usual php file and name it to whatever you want to name it
Important thing is you must remember the name and not wrong when you call it from demo.php or demo.html
Assume you name it domaintool.php and call to show on your website with demo.php,
click here to download both files in zip format and
click here to see the demo . Appreciate if you could give me a link to this site when you run it on your site.
In case
your server haven't php cURL installed , you must do these steps:
change all file_get_contents_curl($url) become file_get_contents($url) except on function file_get_contents_curl($url)
change all do_post_request_curl become do_post_request except on function do_post_request_curl($url, $data)