PHP Code to Get Alexa Rank and Site Linking

IN Shoutmeloud

PHP Code to Get Alexa Rank and Site Linking

Alexa, (an Amazon company), provides traffic data, global traffic rank and other information on websites. It ranks sites based on tracking information of user of its Alexa toolbar. Therefore, only webpages viewed by those with toolbar installed are counted, which makes the data biased. Furthermore, accuracy of low traffic websites may be questionable. Nevertheless, many advertisers and brokers use your Alexa rankings to approve or advertise on your website.

Recommended for you:

In this post, I will explain how to use PHP to get Alexa rank of your blog or website using a simple PHP script. The number can be stored in cache or a database and displayed as simple formatted text. Compared to displaying Alexa widget, it also slightly improves page load speeds. So without further delay, here it goes.

PHP Alexa Rank

PHP Code to Get Alexa Rank

The PHP code to get Alexa rank and sites linking in is pretty simple and straightforward:

Click here for a text version for the code that allows copying.

$source is the variable to hold the link to get information from Alexa about a specific site. Only edit you have to do is replace shoutmeloud.com with your domain name. Alexa rank is now stored in the variable $aresult and sites linking in stored in the variable $alinksin.

After you get alexa rank and sites liking in, you can display them as simple text using the following PHP code:

[code]
echo ‘Alexa Traffic Rank: ‘.$aresult’.'<br>';
echo ‘Alexa Sites Linking In: ‘.$alinksin;
[/code]

This will output:

[code]
Alexa Traffic Rank: 4,881
Alexa sites Linking In: 2,750
[/code]

Alexa Rank History

Although you may be able to get Alexa rank and more by other means, I like to record the data in a format I like. On my blog, I get Facebook like count and Alexa site rank and record them in a MySQL database daily to monitor the growth. For example, if you launched a blog in June 2012 and have recorded the Alexa rank in a database since then, you can use that data to quickly construct a history of your blog’s Alexa rank.

Alexa Rank History

As you can see, having historical data helps one understand how the Alexa rank for their site is trending. If you make any changes / improvements to your blog then you have the data to see what impact it had on your subscribers count and Alexa rank.

So get Alexa rank using the above script, get creative, and find creative ways to use this PHP Alexa rank count Code. Please do not forget to share your idea with us in the comments sections.

This is a guest post by Anand from Linux Explained. If you would like to write for ShoutMeLoud, check our guest posting guidelines.

Subscribe on Youtube

Click to activate Offer & visit site Discount added automatically

Ultimate Blogging Strategies

Sign Up Today For Free

join our site and get free content delivered automatically each time we publish

100% privacy. we will never spam you

  • Author Bio

  • Latest Post

Article by Anand Subramanian

Anand has written 2 articles.

If you like This post, you can follow ShoutMeLoud on Twitter. Subscribe to ShoutMeLoud feed via RSS or EMAIL to receive instant updates.


Testimonials
Send Us Inquiry

Comments

  1. Dean Saliba says

    I actually thought this was going to be a post about how to use PHP code to increase your Alexa Rank for some reason. :P

  2. says

    Really nice Trick… I have implemented this code to one of my blog… and its doing well… thank for sharing this info with us @anand… One thing I would like to ask that “Is it possible to integrate the alexa rank link or review to each pages? Automatically it there is any please tell…

  3. Satish says

    Na, I dont think this will workout pretty well. Instead of that, its better you install the Alexa toolbar and support others doing the same. Messing up the code will screw your page speed and also the theme sometimes. The explanation is pretty unclear. Can you please make a video or something to tell us clearly? Because there is no sense in writing this post, if its not helping us :)

    • Anand Subramanian says

      Satish, thank you for your honest opinion. I agree that Alexa toolbar would help. However, the idea behind the process described in my post is to do more than just the Alexa rank. Please have a look at the link posted in response to Mike and George’s comments. In that post, I have explained how to record other information along with Alexa rank. I am unable to edit this post to update the instructions based on the comments posted. Hope my other post explains the whole process in detail.

    • Anand Subramanian says

      I apolagize if the instructions are not clear. Unfortunately I am unable to edit the original post based on the comments. I have elaborated the whole process in my new post. Please see my response to Mike and George’s comments for link (Sorry I did not want to spam the comments with links).

    • Anand Subramanian says

      Ved Prakash, I do not whether it can increase your alexa rank. But if there is an increase you can see in your record, investigate and find out what you did around that time that resulted in the increase in rank. Hope it makes sense.

  4. George says

    Mate other than replacing the alexa widget and saving some space does it help us in anyway. I am not quite clear on tracking the website growth part measurement. However i was looking for something like this

  5. says

    Nice piece of research Anand. I have already integrated these codes with my blog, and I’m now able to output any of my Alexa data. Thanks for sharing this great post buddy.

    • Anand Subramanian says

      You are very welcome. I have combined Alexa rank with several other parameters and record them daily. It has been very useful to me so far.

  6. Mike Howg says

    This seems interesting. Are there any major benefits of doing it this way other than recording the data in a database?

  7. Tushar Thakur says

    I want to display the alexa rank of my own website on a post. Website running on WordPress . Can you please tell me where to put this code? Many thanks

    • Anand Subramanian says

      Tushar, as explained above. Put the first code block in header.php and the second code block where you want your rank to display.

    • Anand says

      Troy, the first code block (in picture) gets the Alexa info and stores it in the variables $aresult and $alinksin. This has to be done before you display the contents of these variables (as shown in 2nd code block). In essence, the first code block should execute before the second. Going with this logic, yes, you can put the first code block in header.php and the second one (displays the results) where ever you want the Alexa information to appear on your site. Hope this clears it up for you.

    • Anand Subramanian says

      Troy, yes, you can put the first code block in header.php and the second one (displays the results) where ever you want the Alexa information to appear on your site. The first code block (in picture) gets the Alexa info and stores it in the variables $aresult and $alinksin. This has to be done before you display the contents of these variables (as shown in 2nd code block). In essence, the first code block should execute before the second. Hope this clears things up.

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=""> <s> <strike> <strong>