We all know alexa is one of the very popular tool to check website popularity by their rank, It’s traffic rank depends on varies factors, Alexa has given a open url to get some of your’s website traffic data like global and country specific rank, Alexa also provide a paid API to fetch deep analysis of any websites traffic. If you want to improve your website alexa rank read this article of mine: How to improve/increase alexa ranking & why it’s important
Here i created a simple function in php to fetch some basic information of website like their global and country specific rank, You can customize below function as per your need. Alexa has provided public url http://data.alexa.com/data?cli=10&url=[WEBSITE_NAME] to get information about website rank.
Function to fetch website’s alexa data
function alexaRank($url) { $alexaData = simplexml_load_file("http://data.alexa.com/data?cli=10&url=".$url); $alexa['globalRank'] = isset($alexaData->SD->POPULARITY) ? $alexaData->SD->POPULARITY->attributes()->TEXT : 0 ; $alexa['CountryRank'] = isset($alexaData->SD->COUNTRY) ? $alexaData->SD->COUNTRY->attributes() : 0 ; return json_decode(json_encode($alexa), TRUE); } |
Pass any website url on this function and it’ll return their alexa rank. If you want to fetch more information pass one more tag on alexa public url: http://data.alexa.com/data?cli=10&dat=snbamz&url=[WEBSITE_NAME]
Complete code.
index.php
function alexaRank($url) {
$alexaData = simplexml_load_file("http://data.alexa.com/data?cli=10&url=".$url);
$alexa['globalRank'] = isset($alexaData->SD->POPULARITY) ? $alexaData->SD->POPULARITY->attributes()->TEXT : 0 ;
$alexa['CountryRank'] = isset($alexaData->SD->COUNTRY) ? $alexaData->SD->COUNTRY->attributes() : 0 ;
return json_decode(json_encode($alexa), TRUE);
}
?>
|
Simple php based script to fetch website’s alexa rank.
“.$url.” global alexa rank is “.$globalRank.” And Country (“.$alexa[‘CountryRank’][‘@attributes’][‘NAME’].”) rank is “.$countryRank.”“;
}
?>
See live demo and download source code.