[advanced search]
22 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 04-01-2006, 11:16 PM   · #1
123finder.com
NamePros Member
 
Trader Rating: (0)
Join Date: Mar 2006
Posts: 62
NP$: 0.00 (Donate)
123finder.com is an unknown quantity at this point
PHP5 class to get Alexa traffic rank

This PHP5 class utilizes the web service provided by Alexa/Amazon to get the traffic information about the site. You'll need to sign up for an account at Alexa to get the pair (access key and secret key). The first 10,000 queries per month are free.

PHP Code:
<?php
/**
* @author Son Nguyen
* @since 3/31/2006
* @package Framework
* @subpackage WebServices
*/
class CAlexaAPI {
  
private $mParams;
  
private $mSecretKey = 'YOUR SECRET KEY';
  
/** constructor */
  
function __construct() {
    
$this->mParams = array(
      
'Service'=>'AlexaWebInfoService',
      
'AWSAccessKeyId'=>'YOUR ACCESS KEY', // access key id
      
'Operation'=>'UrlInfo',
      
'ResponseGroup'=>'Rank',
      
'Url'=>NULL,
      
'Timestamp'=>gmdate('Y-m-d\TH:i:s.000\Z'),
      
'Signature'=>NULL,
    );
    
$this->prepareSignature();
  }

  
/** ref: http://developer.amazonwebservices.com/connect/thread.jspa?threadID=9675 */
  
private 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))))
    );
  }


  
/** have the signature ready */
  
private function prepareSignature() {
    
$vData = $this->mParams['Service'].$this->mParams['Operation'].$this->mParams['Timestamp'];
    
$this->mParams['Signature'] = $this->calculate_RFC2104HMAC($vData,$this->mSecretKey);
  }
  

  
/** make the rest call and return result as XML object */
  
function call() {
    
$vURL = 'http://awis.amazonaws.com/onca/xml?';
    
$vTmp = array();
    foreach (
$this->mParams AS $vKey=>$vValue) {
      
$vTmp[] = $vKey.'='.$vValue;
    }
// rof
    
$vURL .= implode('&',$vTmp);
    
$vFile = file_get_contents($vURL);
    
$vXML = simplexml_load_string($vFile);
    return
$vXML;
  }

  
/** get the rank for a domain */
  
function getRank($pDomain) {
    
$this->mParams['Url'] = $pDomain;
    
$vResult = $this->call();
    
$vResult = $vResult->UrlInfoResult->Alexa->TrafficData->Rank+0;
    return
$vResult;
  }
}
?>


Please register or log-in into NamePros to hide ads
__________________
123finder.com - Browse dictionary domains & 4-9 letter domains
123finder.com is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


Site Sponsors
Custom Logo Design Proof is in the Parking Proof is in the Parking
Advertise your business at NamePros
All times are GMT -7. The time now is 03:06 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0