We use Alexa’s website (or other webmaster tools website) to block our network Station traffic ranking, so you have to go to those websites.In fact, Alexa-related data (in XML format) can be obtained from Alexa XML API, then XML parser can be used to parse XML returned by Alexa to get Alexa ranking or other data.
Alexa interface
Alexa’s XML API interface is: http://data.alexa.com/data?cli=10 & url=%YOUR_URL%
For more data, you can use: http://data.alexa.com/data?cli=10 & dat=snbamz & url=%YOUR_URL%
Using http://data.alexa.com/data?cli=10 & dat=snbamz & url=ofstack.com returns the following data:
<ALEXA VER="0.9" URL="ofstack.com/" HOME="0" AID="ScELh1AI3f00az" IDN="ofstack.com/">
<RLS PREFIX="http://" more="0"></RLS>
<SD TITLE="A" FLAGS="" HOST="ofstack.com">
<LINKSIN NUM="1"/>
</SD>
<SD>
<POPULARITY URL="ofstack.com/" TEXT="7552101" SOURCE="panel"/>
<REACH RANK="6342897"/>
</SD>
</ALEXA>
The value of the TEXT attribute in the POPULARITY element, 7552101, is the Alexa ranking.
Code implementation:
The code to obtain Alexa rankings from Alexa API using PHP is:
<php>
function getAlexaRank ($Domain){
$line = "";
$data = "";
$URL = "http://data.alexa.com/data/?cli=10&dat=snba&url=". $Domain ;
$fp = fopen ($URL ,"r");
if ($fp ){
while (!feof ($fp )){
$line = fgets ($fp );
$data .= $line ;
}
$p= xml_parser_create ();
xml_parse_into_struct ($p , $data , $vals );
xml_parser_free ($p );
for ($i =0 ;$i <count ($vals );$i ++){
if ($vals [$i ]["tag"]=="POPULARITY"){
return $vals [$i ]["attributes"]["TEXT"];
}
}
}
}
?>
Usage method:
<?php
echo getAlexaRank("ofstack.com");
?>