Welcome folks today in this blog post we will be making a website alexa rank
checker in php using alexa.com
api. All the full source code of the application is given below.
Get Started
In order to get started you need to create an index.php
file inside the root directory and copy paste the following code
index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
<?php function alexaRank($url) { $alexaData = simplexml_load_file("http://data.alexa.com/data?cli=10&url=".$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); } if(isset($_GET['siteinfo'])) { $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']; } ?> <html> <head> <title>Alexa Rank Checker By SadCode</title> <style> body { text-align:center; width:100%; margin:0 auto; padding:0px; font-family:helvetica; background-color:#424242; } #wrapper { text-align:center; margin:0 auto; padding:0px; width:995px; } #rank_form p { color:white; font-size:16px; font-weight:bold; } #rank_form input[type="text"] { width:250px; height:40px; border:none; padding-left:10px; font-size:16px; } #rank_form input[type="submit"] { background-color:#2E2E2E; height:42px; border:none; color:white; width:50px; font-size:16px; } .rank_para { color:white; } </style> </head> <body> <div id="wrapper"> <form method="get" id="rank_form"> <p>Website Yang Mau Di Cek</p> <input type="text" name="siteinfo" placeholder="https://example.com" required="required"/> <input type="submit" value="Find"> </form> <p class="rank_para"><?php echo $globalRank; ?></p> <p class="rank_para"><?php echo $countryRank;?></p> </div> </body> <center>Copyright By SadCode</center> </html> |
And now if you execute the php
script inside the apache
server and browser you will see the following output where you will need to enter the website url with https
prefix and then it will show the alexa global
rank and country rank