StylizedWeb is a blog about web trends and tutorials, KnowHow community forum now maintained by Ross Johnson who also runs a web design company and design blog.

Categories Archive

Popular Posts
Advertisement
Premium WordPress Themes, Theme Galaxy Basecamp
Najbolje ponuda IT poslova u Srbiji na itposlovi.info Advertise on Stylized Web

How to grab Alexa Traffic Rank

add to Save to Delicious Save to Stumble Save to Digg

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

What do you think?





11 Responses so far

By matt
on September 4, 2008

nevermind i figured it out, thanks

By matt
on September 4, 2008

where exactly do i paste this code in?

By buzziboy
on August 12, 2008

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

By mix
on August 9, 2008

NICE :D

By Dejan Cancarevic
on August 8, 2008

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

By Anon
on August 8, 2008

At least give credit where credits due.

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

By Catar4x
on August 5, 2008

change the variable field by :
$domain = $_SERVER[’SERVER_NAME’];

By mohsen
on August 5, 2008

Very useful.
Thanks!

By Rawe
on August 4, 2008

Nice ;)

By Mech
on August 4, 2008

very interesting, i always wondered how to do that!

  1. Nov 6, 2008: not expensive reproduction clock sweepstakes giveaway on the internet