/**
  * Set the User geolocation and page
  */
 function init($link = null, $id = null, $online_time = USER_ONLINE_TIME)
 {
     $file = basename($_SERVER['SCRIPT_FILENAME']);
     $url = $_SERVER['REQUEST_URI'];
     $user_localization = isset($_SESSION['user_localization']) ? $_SESSION['user_localization'] : null;
     $sid = session_id();
     $browser = BROWSER . " " . BROWSER_VERSION;
     $os = BROWSER_OS;
     $ip = IP;
     if (!$user_localization) {
         $time = TIME - HOUR;
         DB::query("DELETE FROM " . DB_PREFIX . "user_localization WHERE time < " . HOUR);
     }
     $user_localization_id = $user_localization ? $_SESSION['user_localization']['user_localization_id'] : DB::get_field("SELECT user_localization_id FROM " . DB_PREFIX . "user_localization WHERE sid='{$sid}'");
     if ($user_id = User::get_user_id()) {
         $guest_id = 0;
         $name = User::get_user_field("name");
     } else {
         $guest_id = isset($user_localization['guest_id']) ? $user_localization['guest_id'] : 1 + DB::get_field("SELECT guest_id FROM " . DB_PREFIX . "user_localization ORDER BY guest_id DESC LIMIT 1;");
         $name = get_msg('guest') . " " . $guest_id;
     }
     if ($user_localization_id) {
         DB::query("UPDATE " . DB_PREFIX . "user_localization SET ip='{$ip}', user_id='{$user_id}', name='{$name}', url='{$url}', id='{$id}', file='{$file}', time='" . TIME . "', sid='{$sid}' WHERE user_localization_id='{$user_localization_id}'");
     } else {
         if (!($location = ip_to_location($ip, $assoc = true))) {
             $location = array('CountryCode' => null, 'CountryName' => null, 'RegionCode' => null, 'RegionName' => null, 'City' => null, 'ZipPostalCode' => null, 'Latitude' => null, 'Longitude' => null, 'TimezoneName' => null, 'Gmtoffset' => null);
         }
         //replace_sql_injection( $location );
         DB::query("INSERT INTO " . DB_PREFIX . "user_localization\r\n                        (ip,sid,user_id,guest_id,name,url,id,file,os,browser,time,time_first_click,country_code,country_name,region_code,region_name,city_name,zip,latitude,longitude,timezone_name,gmt_offset)\r\n                        VALUES\r\n                        ('{$ip}','{$sid}','{$user_id}','{$guest_id}','{$name}','{$url}','{$id}','{$file}','{$os}','{$browser}', " . TIME . ", " . TIME . ", '{$location['CountryCode']}', '{$location['CountryName']}', '{$location['RegionCode']}', '{$location['RegionName']}','{$location['City']}', '{$location['ZipPostalCode']}', '{$location['Latitude']}', '{$location['Longitude']}', '{$location['TimezoneName']}', '{$location['Gmtoffset']}')");
         $user_localization_id = DB::get_last_id();
     }
     $_SESSION['user_localization'] = array('user_localization_id' => $user_localization_id, 'id' => $id, 'guest_id' => $guest_id, 'name' => $name, 'time' => TIME, 'file' => $file, 'user_id' => $user_id, 'os' => $os, 'browser' => $browser);
 }
Example #2
0
 /**
  * Set the User geolocation and page
  */
 function user_where_is_init($id, $link, $online_time = USER_ONLINE_TIME)
 {
     $file = basename($_SERVER['PHP_SELF']);
     $url = $_SERVER['REQUEST_URI'];
     $where_is = isset($_SESSION['where_is']) ? $_SESSION['where_is'] : null;
     $sid = session_id();
     $browser = BROWSER . " " . BROWSER_VERSION;
     $os = BROWSER_OS;
     $ip = get_ip();
     if (!$where_is) {
         $time = TIME - HOUR;
         DB::query("DELETE FROM " . DB_PREFIX . "user_where_is WHERE time < " . HOUR);
     }
     $user_where_is_id = $where_is ? $_SESSION['where_is']['user_where_is_id'] : DB::get_field("SELECT user_where_is_id FROM " . DB_PREFIX . "user_where_is WHERE sid='{$sid}'");
     if ($user_id = $this->get_user_id()) {
         $guest_id = 0;
         $name = $this->get_user_field("name");
     } else {
         $guest_id = isset($where_is['guest_id']) ? $where_is['guest_id'] : 1 + DB::get_field("SELECT guest_id FROM " . DB_PREFIX . "user_where_is ORDER BY guest_id DESC LIMIT 1;");
         $name = _GUEST_ . " " . $guest_id;
     }
     if ($user_where_is_id) {
         DB::query("UPDATE " . DB_PREFIX . "user_where_is SET ip='{$ip}', user_id='{$user_id}', name='{$name}', url='{$url}', id='{$id}', file='{$file}', time='" . TIME . "', sid='{$sid}' WHERE user_where_is_id='{$user_where_is_id}'");
     } else {
         if (!($location = ip_to_location($ip, $type = 'array'))) {
             $location = array('CountryCode' => null, 'CountryName' => null, 'RegionCode' => null, 'RegionName' => null, 'City' => null, 'ZipPostalCode' => null, 'Latitude' => null, 'Longitude' => null, 'TimezoneName' => null, 'Gmtoffset' => null);
         }
         DB::query("INSERT INTO " . DB_PREFIX . "user_where_is\n\t\t\t\t\t\t(ip,sid,user_id,guest_id,name,url,id,file,os,browser,time,time_first_click,country_code,country_name,region_code,region_name,city_name,zip,latitude,longitude,timezone_name,gmt_offset)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t('{$ip}','{$sid}','{$user_id}','{$guest_id}','{$name}','{$url}','{$id}','{$file}','{$os}','{$browser}', " . TIME . ", " . TIME . ", '{$location['CountryCode']}', '{$location['CountryName']}', '{$location['RegionCode']}', '{$location['RegionName']}','{$location['City']}', '{$location['ZipPostalCode']}', '{$location['Latitude']}', '{$location['Longitude']}', '{$location['TimezoneName']}', '{$location['Gmtoffset']}')");
         $user_where_is_id = DB::get_last_id();
     }
     $_SESSION['where_is'] = array('user_where_is_id' => $user_where_is_id, 'id' => $id, 'guest_id' => $guest_id, 'name' => $name, 'time' => TIME, 'file' => $file, 'user_id' => $user_id, 'os' => $os, 'browser' => $browser);
 }