public static function logStat() { if (Yii::$app->user->isGuest && !Yii::$app->session->has('stat')) { $model = Session::find()->where(['id' => Yii::$app->session->id])->one(); if ($model === null) { $model = new Session(); $model->id = Yii::$app->session->id; $model->ip = Yii::$app->request->userIP; $model->user_agent = Yii::$app->request->userAgent; $model->created = $model->modified = time(); $model->save(); } Session::updateAll(['status' => 0], 'modified < :time', [':time' => time() - 15 * 60]); Yii::$app->session->set('stat', true); } }
/** * Creates a new Session model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $this->authorization(); $model = new Session(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }