Get Website Rank using Alexa API

Alexa Internet, Inc. is an American web traffic analysis company based in San Francisco. It is a subsidiary of Amazon. collects data on Internet browsing behavior and transmits them to the Alexa website, where they are stored and analyzed.

Full Source Code for Getting Website Rank using Alexa API

 

<style>
.title{
  font-weight: bold;
  color:#666;
}

.ranking{
  font-size: 24px;
  color:#333;
}
.minus,.plus{
  color:#fff;
  margin-left: 5px;
  padding:4px;
  border-radius: 5px;
}
.minus{
  background: #2bbb0f no-repeat 5px 50%;
}
.plus{
  background: #E41F26 no-repeat 5px 50%;
}
</style>

<form action="" method="get">
  Website URL :<input type="text" name="url">
  <br><br>
  <input type="submit" value="Get Alexa Rank">
</form>


<?php 

  if(isset($_GET['url'])){
    $url = $_GET['url'];

    $api_url = "http://data.alexa.com/data?cli=10&url=".$url;
    $response = file_get_contents($api_url);
    $xml = simple_load_string($response);

    $global_rank = $xml->SD->POPULARITY['TEXT'];
    $country_name = $xml->SD->COUNTRY['NAME'];
    $country_rank = $xml->SD->COUNTRY['RANK'];
    $delta = $xml->SD->RANK['DELTA'];
  }
?>

<h4 class="title">Global Rank</h4>
<p>
  <span class="ranking"><?php echo $global_rank;?></span>
  <?php if($delta<0){ $class="minus";}else{ $class="plus";}?>
  <span class="<?php echo $class;?>">
    <?php echo substr($delta,1);?>
  </span>
</p>


<h4 class="title">Rank in <?php echo $country_name;?></h4>
<p class="ranking"><?php echo $country_rank;?></p>

 



Recommended For You

About the Author: Admin