PDA

View Full Version : Who's Online Enhancement



michael_s
11-17-2010, 04:13 AM
full release finding checks but here is whats needed ASAP to get this going again.

attached zip shows latest whos_online.php but needs your API key adding!

Upgrade from version 3.6.6.2 through too 3.6.7.2
------------

1. Backup files and database!!!

2. register with www.ipinfodb.com

3. find the following 2 lines in admin/whos_online.php and replace these AND all the rest of the function (so lines 157-204 for v3.6.7.1+)

//Function to get IP address geolocation data from IPInfoDB and update whos_online table
function updateIps($ips){

with following :-


//**iBridge start**
$city_precision = true;
$your_api_key = 'replace_with_api_key_from_www.IPInfoDB.com';

//Function to get IP address geolocation data from IPInfoDB and update whos_online table
function updateIps($ips){
global $city_precision, $your_api_key;
//Old,incesure method
//$d = file_get_contents("http://ipinfodb.com/ip_query2.php?ip=$ips");

//Initialize the Curl session
$ch = curl_init();
//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$ipArray = explode(',', $ips);
for($i = 0; $i < sizeof($ipArray); $i++){

if ($city_precision){
$URL = ("http://api.ipinfodb.com/v2/ip_query.php?key=".$your_api_key."&ip=".$ipArray[$i]."&timezone=false");
}else{
$URL = ("http://api.ipinfodb.com/v2/ip_query_country.php?key=".$your_api_key."&ip=".$ipArray[$i]);
}

//Set the URL, then execute, then close
curl_setopt($ch, CURLOPT_URL, $URL);
$d = curl_exec($ch);

//Use backup server if cannot make a connection
// if (!$d){
// //$backup = file_get_contents("http://backup.ipinfodb.com/ip_query2.php?ip=$ips");
// $ch = curl_init();
// $URL = ("http://ipinfodb.com/ip_query2.php?ip=$ips");
// //Set curl to return the data instead of printing it to the browser.
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// //Set the URL, then execute, then close
// curl_setopt($ch, CURLOPT_URL, $URL);
// $backup = curl_exec($ch);
// curl_close($ch);
//
// $answer = new SimpleXMLElement($backup);
// if (!$backup) return false; // Failed to open connection
// }else{
$answer = new SimpleXMLElement($d);
//}
//$nb_results = count($answer->Response);
//for ($i=0;$iIp);
$country_code = mysql_real_escape_string($answer->CountryCode);
$country_name = mysql_real_escape_string($answer->CountryName);
$region_name = mysql_real_escape_string($answer->RegionName);
$city = mysql_real_escape_string($answer->City);
$latitude = mysql_real_escape_string($answer->Latitude);
$longitude = mysql_real_escape_string($answer->Longitude);
$ip_update_sql = "UPDATE `" . TABLE_WHOS_ONLINE . "` SET `country_code` = '$country_code',`country_name` = '$country_name', `region_name` = '$region_name', `city` = '$city', `latitude` = '$latitude', `longitude` = '$longitude' WHERE `ip_address` = '$ip'";
tep_db_query($ip_update_sql);
}

curl_close($ch);
}
//**iBridge end**






3. enter API key received from www.IPInfoDB.com in line 162

4. line 161 set to false if you dont need city info as this will then work even faster (if you have alot of visitors)


More... (http://addons.oscommerce.com/info/824)