Share Pastebin
Guest
Public paste!

n0on3

By: a guest | Feb 9th, 2010 | Syntax: PHP | Size: 3.44 KB | Hits: 18 | Expires: Never
Copy text to clipboard
  1. <?php
  2.  
  3. define('DS','/');
  4. define('VMBP','path to wp-content/plugins/visitor-maps/');
  5. define('TABLE','visitor maps wo table name');
  6.  
  7. function get_country_info($ip){
  8.  
  9.         require_once(VMBP.'include-whos-online-geoip.php');
  10.         $gi = geoip_open_VMWO(VMBP.'GeoLiteCity.dat', VMWO_GEOIP_STANDARD);
  11.         $record = geoip_record_by_addr_VMWO($gi, $ip);
  12.         geoip_close_VMWO($gi);
  13.         $location_info = array();
  14.         $location_info['provider']     = '';
  15.         $location_info['city_name']    = (isset($record->city)) ? $record->city : '';
  16.         $location_info['state_name']   = (isset($record->country_code) && isset($record->region)) ? $GEOIP_REGION_NAME[$record->country_code][$record->region] : '';
  17.         $location_info['state_code']   = (isset($record->region)) ? strtoupper($record->region) : '';
  18.         $location_info['country_name'] = (isset($record->country_name)) ? $record->country_name : '--';
  19.         $location_info['country_code'] = (isset($record->country_code)) ? strtoupper($record->country_code) : '--';
  20.         $location_info['latitude']     = (isset($record->latitude)) ? $record->latitude : '0';
  21.         $location_info['longitude']    = (isset($record->longitude)) ? $record->longitude : '0';
  22.  
  23.         if ( function_exists('utf8_encode') ) {
  24.                 if ($location_info['city_name'] != '' ) {
  25.                         $location_info['city_name'] = utf8_encode($location_info['city_name']);
  26.                 }
  27.                 if ($location_info['state_name'] != '') {
  28.                         $location_info['state_name'] = utf8_encode($location_info['state_name']);
  29.                 }
  30.                 if ($location_info['country_name'] != '') {
  31.                         $location_info['country_name'] = utf8_encode($location_info['country_name']);
  32.                 }
  33.         }
  34.  
  35.         return $location_info;
  36. }
  37.  
  38. function get_query($ip_address,$last_page_url,$user_agent,$current_time){
  39.  
  40.         $http_referer='';
  41.         $user_agent_lower = strtolower($user_agent);
  42.         $name = 'Guest';
  43.         $location_info='';
  44.         $location_info=get_country_info($ip_address);
  45.         if ($location_info != '') {
  46.                $country_name = str_replace("'","",$location_info['country_name']);
  47.                $country_code = str_replace("'","",$location_info['country_code']);
  48.                $city_name    = str_replace("'","",$location_info['city_name']);
  49.                $state_name   = str_replace("'","",$location_info['state_name']);
  50.                $state_code   = str_replace("'","",$location_info['state_code']);
  51.                $latitude     = $location_info['latitude'];
  52.                $longitude    = $location_info['longitude'];
  53.         } else {
  54.                $country_name = '';
  55.                $country_code = '';
  56.                $city_name    = '';
  57.                $state_name   = '';
  58.                $state_code   = '';
  59.                $latitude     = '0.0000';
  60.                $longitude    = '0.0000';
  61.         }
  62.  
  63.         $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');";
  64.  
  65.         echo $query."\n";      
  66.  
  67. }
  68.  
  69. #get_query($ip_address,$last_page_url,$user_agent,$current_time)
  70.  
  71. $q=get_query($argv[1],$argv[2],$argv[3],$argv[4]);
  72. echo "$q \n";
  73.  
  74. ?>