A
A
Anar2016-08-02 23:37:31
Yii
Anar, 2016-08-02 23:37:31

How does yii2 session store if DbSession is not connected?

Hello! I am doing my first project on yii2, the site has authorization and a "remember" function that saves authorization for 30 days. To make remember-me work, I added functions from IdentityInterface to the user model (which extends ActiveRecord implements IdentityInterface):

public static function findIdentity($id)
{
  return self::findOne($id);
}

public function getId()
{
  return $this->User_ID;
}

public static function findIdentityByAccessToken($token, $type = null)
{
  return static::findOne(['access_token' => $token]);
}

public function getAuthKey()
{
  return $this->authKey;
}

public function validateAuthKey($authKey)
{
  return $this->authKey === $authKey;
}

And accordingly when logging in:
Yii::$app->user->login($login_model->getUser(),$login_model->rememberMe());

// Где rememberMe :
public function rememberMe()
{
  return $this->rememberMe ? 3600*24*30 : 0;
}
// из модели login

Can anyone suggest where and in what form, in this scenario, yii2 stores the session?
And is it possible to painlessly transfer all this magic to DbSession? Is it worth doing it at all?
And is it possible to implement the functionality "The user was online / was last on the site" in any of these scenarios? Or is it easier to use Redis right away?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2016-08-03
@qonand

in the standard configuration, yii2 stores the session in files, but you should understand that the "remember" function works not through the session, but through the cookie. Those. when authorizing, an encrypted cookie with an authentication key is set to the user, and when the user revisits the site, it occurs in existing users.
The storage for sessions is naturally configurable. More details about working with sessions in yii are written here

A
Alexander Makarov, 2016-08-03
@SamDark

As set in php.ini. By default in files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question