Beispiel #1
0
 function deviceInfo()
 {
     $client = Client::get_instance();
     // Referral
     $client->referrer = Useragent::referrer();
     // Heavy detections will be cached in cookie
     $cookieStore = array('device', 'browser', 'browserVersion', 'os', 'country', 'city', 'lat', 'lon', 'timezone');
     $device_info_cookie = Cookie::get('device_info');
     if ($device_info_cookie && ($device_info_cookie = json_decode($device_info_cookie))) {
         foreach ($cookieStore as $key) {
             $client->{$key} = $device_info_cookie->{$key};
         }
     } else {
         // Device and browser
         // Use Mobile_Detect for better device recognition
         $client->device = Useragent::is_mobile() ? 'phone' : 'computer';
         $client->browser = Useragent::browser();
         $client->browserVersion = Useragent::version();
         $client->os = Useragent::platform();
         // Geolocation
         // Defaults to Kyiv
         $gb = new IPGeoBase();
         $geo = $gb->getRecord($client->ip);
         $client->country = empty($geo['cc']) ? 'UA' : $geo['cc'];
         $client->city = empty($geo['city']) ? 'Киев' : $geo['city'];
         $client->lat = empty($geo['lat']) ? 50.4501 : $geo['lat'];
         $client->lon = empty($geo['lon']) ? 30.5234 : $geo['lon'];
         $client->timezone = empty($geo['timezone']) ? Config::get('application.timezone', 'Europe/Kiev') : $geo['timezone'];
         $cookieStoreData = new \stdClass();
         foreach ($cookieStore as $key) {
             $cookieStoreData->{$key} = $client->{$key};
         }
         Cookie::make('device_info', json_encode($cookieStoreData), 60 * 60 * 4);
     }
 }