jeger003 Posted November 14, 2012 Share Posted November 14, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/ Share on other sites More sharing options...
Barand Posted November 14, 2012 Share Posted November 14, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392454 Share on other sites More sharing options...
jeger003 Posted November 15, 2012 Author Share Posted November 15, 2012 (edited) i am using rank for other purposes. I really just want to figure how to put this in the db and not one person has been able to determine that. Edited November 15, 2012 by jeger003 Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392585 Share on other sites More sharing options...
Muddy_Funster Posted November 15, 2012 Share Posted November 15, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392589 Share on other sites More sharing options...
jeger003 Posted November 15, 2012 Author Share Posted November 15, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392592 Share on other sites More sharing options...
jeger003 Posted November 15, 2012 Author Share Posted November 15, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392607 Share on other sites More sharing options...
Muddy_Funster Posted November 15, 2012 Share Posted November 15, 2012 what do you get if you do a var_dump of $nice_array where you are currently running your query loops? Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392619 Share on other sites More sharing options...
jeger003 Posted November 15, 2012 Author Share Posted November 15, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392622 Share on other sites More sharing options...
Muddy_Funster Posted November 15, 2012 Share Posted November 15, 2012 do a var_dump of $info for me would you? just at the same place you did the $nice_array one. Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392629 Share on other sites More sharing options...
jeger003 Posted November 15, 2012 Author Share Posted November 15, 2012 object(UrlInfo)[1] public 'name' => string '' (length=0) public 'accessKeyId' => string 'XX' (length=20) public 'secretAccessKey' => string 'XX' (length=40) public 'site' => null public 'StartNum' => null Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392630 Share on other sites More sharing options...
jeger003 Posted November 15, 2012 Author Share Posted November 15, 2012 this is interesting. is there a way to define rank in the urlinfo? would that work? Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392631 Share on other sites More sharing options...
Muddy_Funster Posted November 15, 2012 Share Posted November 15, 2012 that's really not what I was expecting from the xml return.....one last var_dump if you would, this time lets see what's in $response just before you make it into an xmlElement Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392636 Share on other sites More sharing options...
jeger003 Posted November 15, 2012 Author Share Posted November 15, 2012 i tried var_dump($response) var_dump($urlInfo->response) both come back null Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392639 Share on other sites More sharing options...
jeger003 Posted November 15, 2012 Author Share Posted November 15, 2012 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/270696-i-still-dont-understand-class/#findComment-1392666 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.