I’m having a problem, when I logout from either frontend or backend, the other one remains log in. I have been searching online for the solutions but did not find anything like this. What should I change so that when I logout from frontend or backend, the other one must logout.
Log in is working fine for both:
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
My Answer:
user->logout();_ return $this->goHome();_}_In order to ensure that logging out from either the frontend or backend logs out the user from both, you can modify the actionLogout() method in both the frontend and backend controllers to include the following code:_public function actionLogout()_{_ Yii::$app->user->logout();_ Yii::$app->session->destroy();_ return $this->goHome();_}_By adding the line Yii::$app->session->destroy();, you are destroying the session completely, which will log the user out from both the frontend and backend. This should solve the issue of remaining logged in when logging out from one side.
Rate this post
5 of 5 based on 7907 votesComments