/** * Save new record in DB and write unique token in session * * @param int $userId */ public static function newVisitor($userId) { $browser = new Browser(); $model = new self(); $model->user_id = $userId; $model->token = uniqid(); $model->ip = LittleBigHelper::getRealIp(); $model->language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : null; $model->browser = $browser->getBrowser(); $model->os = $browser->getPlatform(); $model->user_agent = $browser->getUserAgent(); $model->visit_time = time(); $model->save(false); Yii::$app->session->set(self::SESSION_TOKEN, $model->token); }
/** * @return string */ public function getBrowser() { $browser = new Browser(); $navigateurFinal = explode('.', $browser->getVersion()); return strtolower($browser->getBrowser() . ' ' . $browser->getBrowser() . $navigateurFinal[0]) . ' ' . $browser->getPlatform(); }