StylizedWeb is a web design trends and tutorials blog, maintained by Ross Johnson who also runs a web design company and design blog.

Categories Archive

Popular Posts
Advertisement
Basecamp The Web Design Sketchbook
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'); 
 
?>
 

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



Talk of the town
  • South West Balloon Flights: Thanks for the script. Looks nice.
  • Tony: How about WP Super Cache. Google now takes into account a site’s loading time and what better way to...
  • Emek Elektrik: Thanks Adminstrator For Dar Gelirli Users…
  • Nelly: That is a good article for css thank you admin
  • Nelly: I want to learn css Can anyone help me? Thanks a lot
Amigos

What do you think?





17 Responses so far

By kpss10
on April 22, 2009

Nice Stuff! Thanks man

By chandu
on February 24, 2009

how to use this code – where to past ?

By komik oyunlar
on February 21, 2009

nice blog thanks

By giydirme
on February 21, 2009

ı 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.

By slym
on February 14, 2009

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

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. Jan 21, 2009: louisville ky printable credit reports
  2. Nov 6, 2008: not expensive reproduction clock sweepstakes giveaway on the internet