Fetch alexa rank using php script

alexa-rank-php

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.
alexa-rank-php

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);
}
?>



  Alexa Rank checker tool in php
  
  


Simple php based script to fetch website's alexa rank.


if(isset($_REQUEST['siteinfo'])) { $url = $_REQUEST['siteinfo']; $alexa = alexaRank($url); $globalRank = isset($alexa['globalRank'][0]) ? $alexa['globalRank'][0] : 'N/A'; $countryRank = isset($alexa['CountryRank']['@attributes']['RANK']) ? $alexa['CountryRank']['@attributes']['RANK'] : 'N/A'; echo ".$url." global alexa rank is ".$globalRank." And Country (".$alexa['CountryRank']['@attributes']['NAME'].") rank is ".$countryRank.""; } ?>

Alexa Rank checker tool in php

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.

If you like this post please don’t forget to subscribe my public notebook for more useful stuff

Leave a Reply

Your email address will not be published. Required fields are marked *

Top