StylizedWeb

Subscribe to our updates:

A Design, WordPress and Tutorials Blog.

Dedicated to helping you learn the art and science of the web.

How to grab Alexa Traffic Rank

If you don't have Alexa toolbar i'm sure you have seen somewhere a rank according to it, for example on BuySellAds etc... The traffic rank is based on three months of aggregated historical traffic data from millions of Alexa Toolbar users and data obtained from other, diverse traffic data sources, and is a combined measure of page views and users (reach).

So if you need it for some professional services or dunno just for fun (like me, so far) here's the code for it ready for copy/paste and just change the url.

 
<?
 
class alexa {
 
    var $xml;
    var $values;
    var $alexa_address;
 
    function alexa($alexa_address,$domain) {
        $this->alexa_address = $alexa_address;
        $this->xml = $this->get_data($domain);
        $this->set();
    }
 
    function get_data($domain) {
        $url = $this->alexa_address.'http://'.$domain;
        $xml = simplexml_load_file($url) or die('Cannot retrieve feed');
        return $xml;
    }
 
    function set() {
        $this->values['rank'] = ($this->xml->SD->POPULARITY['TEXT'] ? number_format($this->xml->SD->POPULARITY['TEXT']) : 0);
    }
 
    function get($value) {
        return (isset($this->values[$value]) ? $this->values[$value] : '"'.$value.'" does not exist.');
    }
}
 
$domain = "stylizedweb.com";
$alexa_connector = new alexa('http://alexa.com/xml/dad?url=',$domain);
echo 'alexa rank for '.$domain.' is '.$alexa_connector->get('rank'); 
 
?>
 

Leave a comment on Stylized Web Have some feedback? Leave a comment

23 Comments So Far

  1. By Mech posted on August 4, 2008 at 8:06 pm

    very interesting, i always wondered how to do that!

  2. By Rawe posted on August 4, 2008 at 8:06 pm

    Nice ;)

  3. Very useful.
    Thanks!

  4. change the variable field by :
    $domain = $_SERVER['SERVER_NAME'];

  5. By Anon posted on August 8, 2008 at 7:27 pm

    At least give credit where credits due.

    http://davidwalsh.name/php-alexa-rank-fetcher-xml

  6. By Dejan Cancarevic posted on August 8, 2008 at 7:35 pm

    Thanks for the link, i didn’t know who’s the original author

  7. By mix posted on August 9, 2008 at 7:08 pm

    NICE :D

  8. Great information, thanks for sharing it with us. i will try it out for my newly kids portal http://www.buzziboy.com

  9. where exactly do i paste this code in?

  10. nevermind i figured it out, thanks

  11. Pingback: not expensive reproduction clock sweepstakes giveaway on the internet

  12. Pingback: louisville ky printable credit reports

  13. 70% of the time of website owner is consumed in experimenting towards increasing page rank and alexa rank. To start with increasing page rank one must start with downloading Alexa toolbar for IE or firefox on as many system possible. as a second step alexa widget on every page of your website, by this way every webpage opened is counted while calculating rank inspite is user does not have alexa toolbar installed knowtheworldaround.com

  14. ı have followed your writing for a long time.really you have given very successful information.
    In spite of my english trouale,I am trying to read and understand your writing.
    And ı am following frequently.I hope that you will be with us together with much more scharings.
    I hope that your success will go on.

  15. nice blog thanks

  16. how to use this code – where to past ?

  17. Nice Stuff! Thanks man

  18. useful information thanks

  19. Pretty good list, I’m just glad it’s concise.

  20. interesting post. good article thanks admin.

  21. sorry i should put it befor buddy? i mean in header?

  22. By ying posted on August 29, 2011 at 10:25 am
  23. wow amazing i love it ..perfect..

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>