• X

    PHP Code to Get Alexa Rank and Site Linking

    By in Design

    Bluehost hosting

    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.

    Alexa Information SML PHP Code to Get Alexa Rank and Site Linking

    PHP Code to Get Alexa Rank

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

    Alexa Rank Code SML PHP Code to Get Alexa Rank and Site Linking

    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:

    echo 'Alexa Traffic Rank: '.$aresult'.'<br>';
    echo 'Alexa Sites Linking In: '.$alinksin;
    

    This will output:

    Alexa Traffic Rank: 4,881
    Alexa sites Linking In: 2,750
    

    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 SML PHP Code to Get Alexa Rank and Site Linking

    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.

    Get Free Blogging updates in your Email

    Find more Topics based on Keywords

    Article by

    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.

    { 22 comments… read them below or add one }

    troy janda

    where do you insert the code? Header.php, functions.php?

    Reply

    Anand

    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.

    Reply

    Anand Subramanian

    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.

    Reply

    Tushar Thakur

    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

    Reply

    Anand Subramanian

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

    Reply

    Mike Howg

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

    Reply

    Anand Subramanian

    Mike, having a history of the ranks help a lot. For example, if you decide to write a guest post for a certain website, you can monitor the rank or facebook like count or other parameters to see what the impact wast. Please take a look at this post see how it could help you:

    http://linuxplained.com/track-alexa-facebook-twitter-feedburner-stats/

    Reply

    PrIyAnGsHu

    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.

    Reply

    Anand Subramanian

    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.

    Reply

    George

    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

    Reply

    Anand Subramanian

    George, I recently published another details post describing how to record and track not only Alexa rank but several others like, Twitter followers count, Facebook Likes count, FeedBurner subscriptions count. Hope it provides more details for you and helps you out:

    http://linuxplained.com/track-alexa-facebook-twitter-feedburner-stats/

    Reply

    ved prakash Joshi

    Awesome trick man…
    May we would be able to increase our alexa ranking as well using this trick

    Reply

    Anand Subramanian

    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.

    Reply

    Hemant

    Please tell me the plugin you use for others management.

    Reply

    Tushar Thakur

    I tried eveything but how to do it in wordpress?

    Reply

    Anand Subramanian

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

    Reply

    Satish

    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 :)

    Reply

    Anand Subramanian

    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.

    Reply

    Abuzar

    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…

    Reply

    Dean Saliba

    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

    Reply

    Osho Garg

    @Anand Is There Any Way To Use This Code In Blogger Blog ?

    Reply

    Affan Ruslan

    I’d suggest you make a shortcode, so user can output it anywhere they want it (post, page etc)

    Reply

    Leave a Comment

    Previous post:

    Next post:

    `