PHP Script to get Alexa Rank

Alexa traffic rank is a value given to any website by alexa based on it’s traffic. A lower traffic rank means higher traffic volume to a website. Alexa is providing an paid API to access it database. But there is a way to do this for free. To get this data in XML format use following URL

http://data.alexa.com/data?cli=10&dat=snbamz&url=<yourwebsite.com>

To parse this XML file either you can use regular expression match or use inbuilt php5 function simplexml_load_file. here i am doing this with simplexml_load_file

PHP code to get Alexa Rank

<?
$url='toolspot.org';
$xml = simplexml_load_file('http://data.alexa.com/data?cli=10&dat=snbamz&url='.$url);
$rank=isset($xml->SD[1]->POPULARITY)?$xml->SD[1]->POPULARITY->attributes()->TEXT:0;
$web=(string)$xml->SD[0]->attributes()->HOST;
echo $web." has Alexa Rank ".$rank;
?>

To get other info like alexa backlinks, website load time, dmoz listing etc, use similar method to parse XML

Eg: To get alexa backlink

$backlink=(int)$xml->SD[0]->LINKSIN->attributes()->NUM;

Alexa Rank checker Demo


Liked It? Get Free updates in your Email

Delivered by feedburner

10 thoughts on “PHP Script to get Alexa Rank

  1. abcd
    #

    woww its working. Thank you so much

    Reply
  2. Odie
    #

    I use wordpress, where I had to put the above code?

    Reply
    1. gvzcvx
      #

      you put the code on your website LOL

      Reply
  3. Rhoula
    #

    I’ve made a little script that lets you add the Alexa Rank to a Mysql database.

    The script is nothing big. I was wishing to share it in exchange of small donations. The reason I’m asking for donations is because I’m having a little trouble taking care of my household and I’m hoping to go 100% freelancing.

    Thank you for being understanding.

    Have a wonderful day.

    Reply
  4. Ahmed
    #

    Boooom. WOrking Script Bro Thank You Soo Much.

    Reply
  5. akash
    #

    super its working..

    Reply
  6. clasificados cuba
    #

    Great post, I made an imrpoved version of this and I like to share.

    private function getAlexaRank($domain_name = ‘bachecubano.com’)
    {
    $xml = simplexml_load_file(‘http://data.alexa.com/data?cli=10&dat=snbamz&url=’ . $domain_name);

    $rank = isset($xml->SD[1]->POPULARITY) ? $xml->SD[1]->POPULARITY->attributes()->TEXT : 0;
    //$web = (string)$xml->SD[0]->attributes()->HOST;
    $reach = isset($xml->SD[1]->POPULARITY) ? $xml->SD[1]->REACH->attributes()->RANK : 0;
    $delta = isset($xml->SD[1]->POPULARITY) ? $xml->SD[1]->RANK->attributes()->DELTA : 0;

    return [‘rank’ => $rank, ‘reach’ => $reach, ‘delta’ => $delta];
    }

    So just call it by var_dump($this->getAlexaRank(‘your_domain_name.com’));

    Thanks!

    Reply
  7. thalhah
    #

    Hi, still can use in 2017?

    Reply
    1. Sunny Post author
      #

      Yes its still working

      Reply

Leave a Reply

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