How to store user in cookies?

When the user logs on so Yii::$app->user->login($user);
it is not by default stored in cookies how to make what he'd survived???
July 9th 19 at 12:46
2 answers
July 9th 19 at 12:48
Solution
Not safe to store user in cookies. Cookies can whistle or to replace and what you will do in this case?

The info of the current logged-in user can be obtained as
Yii::$app->user->identity->id well, or something else. if not Id. Lightweight request and solves a lot of issues by obtaining current Affairs.
And how do I save the user after the browser is closed? - alphonso_Abbott commented on July 9th 19 at 12:51
In the cookie to store the user session ID to the browser is closed the user authentication is active, you need to set the lifetime of cookies, if the time is not, as in Your version of the cook after closing the browser destroyed. Read the documentation about user authentication in Yii, there is a moment of realization of the cookies described - adell17 commented on July 9th 19 at 12:54
: Thank you - alphonso_Abbott commented on July 9th 19 at 12:57
July 9th 19 at 12:50
Solution
/**
 * Logs in the user using the given username and password in the model.
 * @return boolean whether login is successful
*/
 public function login($is_front = false)
{
 if ($this->_identity === null) {
 $this->_identity = new UserIdentity($this->username, $this->password);
$this->_identity->authenticate();
}
 if ($this->_identity->errorCode === UserIdentity::ERROR_NONE) {
 $duration = $this->rememberMe ? 3600 * 24 * 30 : 0; // 30 days
 Yii::app()->user->login($this->_identity, $duration);
 return true;
 } else
 return false;
 }
: > And how do I save the user after the browser is closed?

$duration = $this->rememberMe ? 3600 * 24 * 30 : 0; // 30 days <-- here it is storing a cookie with the authorization for 30 days - alphonso_Abbott commented on July 9th 19 at 12:53
: I specify the duration but after the browser is closed the cookie is not present - adell17 commented on July 9th 19 at 12:56
: it is necessary to examine what the server sends and what happens after closing/opening browser. Find me on Skype. - alphonso_Abbott commented on July 9th 19 at 12:59

Find more questions by tags Yii