How to Find Alexa Rank of any Website using PHP

Alexa traffic rank is a value given to any website by alexa based on it’s traffic. A lower traffic rank means higher traffic volume to a website. Alexa is providing an paid API to access it database. But there is a way to do this for free. To get this data in XML format use following URL. You may also like How to Interval Timer Countdown using setTimeout().

PHP Code

$globalRank = '';
$countryRank = '';
function alexaRank($url) 
    $alexaData = simplexml_load_file("".$url);
    $alexa['globalRank'] =  isset($alexaData->SD->POPULARITY) ? $alexaData->SD->POPULARITY->attributes()->TEXT : 0 ;
    $alexa['CountryRank'] =  isset($alexaData->SD->COUNTRY) ? $alexaData->SD->COUNTRY->attributes() : 0 ;
    return json_decode(json_encode($alexa), TRUE);

    $url = $_GET['siteinfo'];
    $alexa = alexaRank($url);
    $globalRank ="Global Alexa Rank of ".$_GET['siteinfo']." is : ".$alexa['globalRank'][0];
    $countryRank ="Alexa Rank In ".$alexa['CountryRank']['@attributes']['NAME']." is : ".$alexa['CountryRank']['@attributes']['RANK'];

        <form method="get" id="rank_form">
            <p>Enter Website To Get Alexa Rank</p>
            <input type="text" name="siteinfo" placeholder="E.g." required="required"/>
            <input type="submit" value="Find">

        <p><?php echo $globalRank; ?></p>
        <p><?php echo $countryRank; ?></p>

Leave a Reply

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