n0on3
By: a guest | Feb 9th, 2010 | Syntax:
PHP | Size: 3.44 KB | Hits: 18 | Expires: Never
<?php
define('VMBP','path to wp-content/plugins/visitor-maps/');
define('TABLE','visitor maps wo table name');
function get_country_info($ip){
require_once(VMBP.'include-whos-online-geoip.php');
$gi = geoip_open_VMWO(VMBP.'GeoLiteCity.dat', VMWO_GEOIP_STANDARD);
$record = geoip_record_by_addr_VMWO($gi, $ip);
geoip_close_VMWO($gi);
$location_info = array();
$location_info['provider'] = '';
$location_info['city_name'] = (isset($record->city)) ?
$record->city : '';
$location_info['state_name'] = (isset($record->country_code) && isset($record->region)) ?
$GEOIP_REGION_NAME[$record->country_code][$record->region] : '';
$location_info['state_code'] = (isset($record->region)) ?
strtoupper($record->region) : '';
$location_info['country_name'] = (isset($record->country_name)) ?
$record->country_name : '--';
$location_info['country_code'] = (isset($record->country_code)) ?
strtoupper($record->country_code) : '--';
$location_info['latitude'] = (isset($record->latitude)) ?
$record->latitude : '0';
$location_info['longitude'] = (isset($record->longitude)) ?
$record->longitude : '0';
if ($location_info['city_name'] != '' ) {
$location_info['city_name'] = utf8_encode($location_info['city_name']);
}
if ($location_info['state_name'] != '') {
$location_info['state_name'] = utf8_encode($location_info['state_name']);
}
if ($location_info['country_name'] != '') {
$location_info['country_name'] = utf8_encode($location_info['country_name']);
}
}
return $location_info;
}
function get_query($ip_address,$last_page_url,$user_agent,$current_time){
$http_referer='';
$name = 'Guest';
$location_info='';
$location_info=get_country_info($ip_address);
if ($location_info != '') {
$country_name = str_replace("'","",$location_info['country_name']);
$country_code = str_replace("'","",$location_info['country_code']);
$city_name = str_replace("'","",$location_info['city_name']);
$state_name = str_replace("'","",$location_info['state_name']);
$state_code = str_replace("'","",$location_info['state_code']);
$latitude = $location_info['latitude'];
$longitude = $location_info['longitude'];
} else {
$country_name = '';
$country_code = '';
$city_name = '';
$state_name = '';
$state_code = '';
$latitude = '0.0000';
$longitude = '0.0000';
}
$query = "INSERT IGNORE INTO " . TABLE . " (session_id,ip_address,user_id,name,country_name,country_code,city_name,state_name,state_code,latitude,longitude,last_page_url,http_referer,user_agent,hostname,time_entry,time_last_click,num_visits)values ('" . $ip_address . "','" . $ip_address . "','" . $wo_user_id . "','" . $name . "','" . $country_name . "','" . $country_code . "','" . $city_name . "','" . $state_name . "','" . $state_code . "','" . $latitude . "','" . $longitude . "','" . $last_page_url . "','" . $http_referer . "','" . $user_agent . "','" . $hostname . "','" . $current_time . "','" . $current_time . "','1');";
echo $query."\n";
}
#get_query($ip_address,$last_page_url,$user_agent,$current_time)
$q=get_query($argv[1],$argv[2],$argv[3],$argv[4]);
echo "$q \n";
?>