Unstoppable Domains

PHP4 script to get Alexa Traffic Rankings

Spacemail by SpaceshipSpacemail by Spaceship
Watch

sacx13

Established Member
Impact
3
The primarly code was found on: http://www.checkurl.info

Code:
function Alexa($domain) {
    //define vars
    $return = 0;
    $serviceURL = 'http://awis.amazonaws.com/onca/xml';

    $service = "AlexaWebInfoService";
    $operation = "UrlInfo";
    $timestamp = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()); // Timestamp format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
    $signature = '';
    $secretAccessKey = 'YOUR SECRET KEY';
    $signature = urlencode(calculate_RFC2104HMAC($service.$operation.$timestamp,$secretAccessKey));
    $timestamp = urlencode($timestamp);

    // construct the query
    $q = '?Service='.$service
        .'&AWSAccessKeyId=YOUR PUBLIC KEY'
        .'&Operation='.$operation
        .'&ResponseGroup=Rank'
        .'&Url=www.'.$domain
        .'&Timestamp='.$timestamp
        .'&Signature='.$signature;

    // get the xml results
    $fetchURL = $serviceURL.$q;

    if(!$xml = @file_get_contents($fetchURL)) {
        $file = @file($fetchURL);
        $xml = implode("", $file);
    }
//    echo $xml;
    // if the result was invalid, meaning API key expired
    if(strstr('<IsValid>False</IsValid>', $xml)) {
        $xml = '<Rank>-1</Rank>';
    }

    // find the rank
    preg_match('/\<Rank\>(\d+)\<\/Rank\>/', $xml, $result);
    $return = $result[1];

    // return the results
    return "$return";
}

function calculate_RFC2104HMAC ($data, $key) {
    return base64_encode (
        pack("H*", sha1((str_pad($key, 64, chr(0x00))
        ^(str_repeat(chr(0x5c), 64))) .
        pack("H*", sha1((str_pad($key, 64, chr(0x00))
        ^(str_repeat(chr(0x36), 64))) . $data))))
     );
}
How to use:

Code:
 $apr=Alexa("namepros.com");
 echo "Alexa Rank for namepros.com is: ".$apr."<br>";

Regards
Adrian

P.S. Any NP$ is welcome :)
P.P.S. Any problem write me on PM or here in forum
 
1
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
Thanks for the script! A pretty good one!
 
0
•••
I just maked work... The script is not made by me.

Regards :)
 
0
•••
What is the secret key?
 
0
•••
0
•••
Guess I'll have to get me one of those.
 
0
•••
If people need a simple solution, you can query:

query said:
http://www.stscac.com/dev/alexa/?url=x

x = http://www.domain.com or http://domain.com or domain.com

For those of you who want the rank without having to worry about any code or the bulky alexa site.

-Steve
 
0
•••
stscac said:
If people need a simple solution, you can query:
http://www.stscac.com/dev/alexa/?url=x

For those of you who want the rank without having to worry about any code or the bulky alexa site.

-Steve

That's cool you set this up. Newbie developers could use file_get_contents with that URL if they wanted a checker or something. Here's an example for PHP-illiterate folks of how to use this in their scripts.

<?
if (isset($_POST['submit'])) {
$str = file_get_contents("http://www.stscac.com/dev/alexa/?url=".$_POST['url']);
$str = trim($str);
echo "Rating for ".$_POST['url']." is ".$str;
}
else
{
?>
<form name="alexarate" method="post" action="<?=$_SERVER['PHP_SELF']; ?>">
Get Alexa Rating For:
<input type="text" name="url" value="http://"> <input type="submit" name="submit" value="Get Rating!">
</form>
<?
}
?>
 
0
•••
there are also versions that doesn't require AWS developer's key
 
0
•••
weblord said:
there are also versions that doesn't require AWS developer's key

I'm sure you can develop your own API that communicates with the Alexa site directly. I might script up something for the users at NP when I'm not so tired ;)
 
0
•••
weblord said:
there are also versions that doesn't require AWS developer's key
Yep ;) :D
 
0
•••
Thanks for this script, i know you didnt make it but i will give you rep for finding it.
 
0
•••
webbist101 said:
stscac said:
If people need a simple solution, you can query:
http://www.stscac.com/dev/alexa/?url=x

For those of you who want the rank without having to worry about any code or the bulky alexa site.

-Steve

That's cool you set this up. Newbie developers could use file_get_contents with that URL if they wanted a checker or something. Here's an example for PHP-illiterate folks of how to use this in their scripts.

<?
if (isset($_POST['submit'])) {
$str = file_get_contents("http://www.stscac.com/dev/alexa/?url=".$_POST['url']);
$str = trim($str);
echo "Rating for ".$_POST['url']." is ".$str;
}
else
{
?>
<form name="alexarate" method="post" action="<?=$_SERVER['PHP_SELF']; ?>">
Get Alexa Rating For:
<input type="text" name="url" value="http://"> <input type="submit" name="submit" value="Get Rating!">
</form>
<?
}
?>
That's the reason I did it. I remember when I was a rather newbie when it came to web development, and I do remember people helping out and helping me learn different functions through examples.

I figure that some people will not be able to understand the code in the first example, I'll make it a little more bearable for them. ;)

I'm not asking for anything at this time, but just let me know what site you're pulling the data to so I can keep track.

:)

-Steve
 
0
•••
stscac said:
That's the reason I did it. I remember when I was a rather newbie when it came to web development, and I do remember people helping out and helping me learn different functions through examples.

I figure that some people will not be able to understand the code in the first example, I'll make it a little more bearable for them. ;)

I'm not asking for anything at this time, but just let me know what site you're pulling the data to so I can keep track.

:)

-Steve

Yeah, I can see this becoming a problem. However, I doubt many sites recieving any serious traffic would still use your system, as they would be on a high enough budget to afford developers to do this theirselves.
 
0
•••
webbist101 said:
Yeah, I can see this becoming a problem. However, I doubt many sites recieving any serious traffic would still use your system, as they would be on a high enough budget to afford developers to do this theirselves.
I figured this much. But for those who do use it, just drop me a line.

-Steve
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back