Jump to content

Recommended Posts

i am using a alexa aws script to get the rank of domains. the output wont allow me to place the rank into a db. comes up blank. I dont really understand how it works but I have managed to tweak to fit my needs. I just need to put the data in a database.

 

class page


class UrlInfo {

   public static $ActionName        = 'TrafficHistory';
   public static $ResponseGroupName = 'History';
   public static $ServiceHost      = 'awis.amazonaws.com';
   public static $NumReturn         = 10;
   //public static $StartNum          = "2012-04-01";
   public static $SigVersion        = '2';
   public static $HashAlgorithm     = 'HmacSHA256';
   var $name = "";

   public function UrlInfo($accessKeyId, $secretAccessKey, $site, $StartNum) {
       $this->accessKeyId = $accessKeyId;
       $this->secretAccessKey = $secretAccessKey;
       $this->site = $site;
       $this->StartNum = $StartNum;
   }

   /**
    * Get site info from AWIS.
    */ 
   public function getUrlInfo() {
       $queryParams = $this->buildQueryParams();
       $sig = $this->generateSignature($queryParams);
       $url = 'http://' . self::$ServiceHost . '/?' . $queryParams . 
           '&Signature=' . $sig;
       $ret = self::makeRequest($url);
       //echo "\nResults for " . $this->site .":\n\n <br>";
       self::parseResponse($ret);
   }

   /**
    * Builds current ISO8601 timestamp.
    */
   protected static function getTimestamp() {
       return gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()); 
   }

   /**
    * Builds query parameters for the request to AWIS.
    * Parameter names will be in alphabetical order and
    * parameter values will be urlencoded per RFC 3986.
    * @return String query parameters for the request
    */
   protected function buildQueryParams() {


       $params = array(
           'Action'            => self::$ActionName,
           'ResponseGroup'     => self::$ResponseGroupName,
           'AWSAccessKeyId'    => $this->accessKeyId,
           'Timestamp'         => self::getTimestamp(),
           'Count'             => self::$NumReturn,
           'Start'             => $this->StartNum,
           'SignatureVersion'  => self::$SigVersion,
           'SignatureMethod'   => self::$HashAlgorithm,
           'Url'               => $this->site
       );
       ksort($params);
       $keyvalue = array();
       foreach($params as $k => $v) {
           $keyvalue[] = $k . '=' . rawurlencode($v);
       }
       return implode('&',$keyvalue);
   }

   /**
    * Makes request to AWIS
    * @param String $url   URL to make request to
    * @return String       Result of request
    */



        protected static function makeRequest($url) {

               //echo "\nMaking request to:\n$url\n <br><br>";

               $result = file_get_contents($url);//'wget -bq -o /dev/null $url >/dev/null 2>&1';

               return $result;

       } 




//    protected static function makeRequest($url) {
//        echo "\nMaking request to:\n$url\n";
//        $ch = curl_init($url);//'wget -bq -o /dev/null $url >/dev/null 2>&1';
//        curl_setopt($ch, CURLOPT_TIMEOUT, 4);
//        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//        $result = curl_exec($ch);
//        curl_close($ch);
//        return $result;
//    }

   /**
    * Parses XML response from AWIS and displays selected data
    * @param String $response    xml response from AWIS
    */
   public static function parseResponse($response) {
       $xml = new SimpleXMLElement($response,null,false,
                                   'http://awis.amazonaws.com/doc/2005-07-11');
       if($xml->count() && $xml->Response->TrafficHistoryResult->Alexa->count()) {
           $info = $xml->Response->TrafficHistoryResult->Alexa;
           $nice_array = array(
               // 'Phone Number'   => $info->ContactInfo->PhoneNumbers->PhoneNumber,
               // 'Owner Name'     => $info->ContactInfo->OwnerName,
               // 'Email'          => $info->ContactInfo->Email,
//                 'Street'         => $info->ContactInfo->PhysicalAddress->Streets->Street,
//                 'City'           => $info->ContactInfo->PhysicalAddress->City,
//                 'State'          => $info->ContactInfo->PhysicalAddress->State,
//                 'Postal Code'    => $info->ContactInfo->PhysicalAddress->PostalCode,
//                 'Country'        => $info->ContactInfo->PhysicalAddress->Country,
//                 'Links In Count' => $info->ContentData->LinksInCount,
//                 'Rank'           => $info->TrafficData->Rank,
//                 'Usage'          => $info->TrafficData->UsageStatistics
                   'Rank'          => $info->TrafficHistory->HistoricalData->Data->Rank
               //'GOOGLE LINKS'   => $info->ContentData->SitesLinkingInResult
           );
       }

                  foreach($nice_array as $k => $v) 
                   {
                       echo $k.': ' . $v ."\n <br>";
                      $insert = mysql_query("SELECT MAX(id) AS MxID FROM rank") or die(mysql_error());

                      while($id = mysql_fetch_array($insert))
                      {
                       mysql_query("UPDATE rank SET rank = '".$_GET['lastrank']."' WHERE id = '".$id['MxID']."' ");
                      }


                   }

   }

   /**
    * Generates an HMAC signature per RFC 2104.
    *
    * @param String $url       URL to use in createing signature

   */




   protected function generateSignature($url) {
       $sign = "GET\n" . strtolower(self::$ServiceHost) . "\n/\n". $url;
       //echo "String to sign: \n" . $sign . "\n";
       $sig = base64_encode(hash_hmac('sha256', $sign, $this->secretAccessKey, true));
       //echo "\nSignature: " . $sig ."\n";
       return rawurlencode($sig);
   }

}

 

I need to store data of

 

 

$urlInfo = new UrlInfo($accessKeyId, $secretAccessKey, $site, $StartNum);

$urlInfo->getUrlInfo();

 

 

i would appreciate any help.

Link to comment
https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/
Share on other sites

Rank is normally determined by position in an ordered set based on another value.

 

As such it is derived data, continually subject to change, and therefore doesn't belong in the database but should be calculated when required.

I don't see you open a connection to a database anywhere, I don't know what you expect to find inside $_GET['lastrank'], I don't know whay the hell you are running the select query inside a loop and the update query in a loop inside the other loop (even thought the second loop will only have a single itteration, i do know that at no point to you try to put any value from $nice_array[] into the database.

the reason i did that is because thats the only place i can put rank in the db. the out of $urlInfo->getUrlInfo(); is $k.': ' . $v or Rank : 4321 I just cant figure out how to call on the $nice_arrary to output just the rank. when I put $urlInfo->getUrlInfo(); into a url or query to the db it comes up blank. so i put the query within the for each cause for some reason thats the only place it works.

I have tried just about about everything. the only time it outputs the rank is when i use $urlinfo->geturlinfo(). I have tried $urlinfo->nice_array and $urlinfo->parseResponse I just dont understand why it wont let me store the data anywhere. i can't even put it in a url so <a href=/'"$urlinfo->getUrlInfo()."'>Rank</a> does not work either

what do you get if you do a var_dump of $nice_array where you are currently running your query loops?

 

it gives me trying to get property of non-object. so far here is what i did

 


   $accessKeyId1 = "XXX";
   $secretAccessKey1 = "XXX";
   $site1 = $_GET['domain'];
   $StartNum1 = $_GET['currentdate']; 

   //$url = $urlInfo->getUrlInfo();
   //echo "URL : ".$url;  

   function Rank($accessKeyId, $secretAccessKey, $site, $StartNum)
   {$urlInfo = new UrlInfo($accessKeyId, $secretAccessKey, $site, $StartNum); $urlInfo->getUrlInfo();}
   //echo "test:<a href='/";
   $test = Rank($accessKeyId1, $secretAccessKey1, $site1, $StartNum1);

 

this allows me to place the rank inside a href="?rank=$test but it wont allow me to use inside

 

header("Refresh: 5, url=?currentdate=$nextDate&domain=$nextDomain&lastrank='".Rank($accessKeyId1, $secretAccessKey1, $site1, $StartNum1)."'&runtime=$nextRuntime");

 

tried Rank($accessKeyId1, $secretAccessKey1, $site1, $StartNum1) and $test.

 

this makes absolutely no sense why it wont let me store it in the mysql or even use it in the header. could this be something amazon is trying to prevent?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.