Sessions in Yii
43,341
Solution 1
For creating yii session
Yii::app()->session['userid'] = "value";
You can get value like this
$sleep = Yii::app()->session['userid'];
And unset session like
unset(Yii::app()->session['userid']); # Remove the session
In case of user signs out , you have to remove all the session.
Yii::app()->session->clear();
After this, you need to remove actual data from server
Yii::app()->session->destroy();
Solution 2
Don't clear session, only logout:
Yii::app()->user->logout(false);
Related videos on Youtube
Author by
Tested
Updated on January 08, 2020Comments
-
Tested over 4 years
Here I go what am doing is I am using
Yii::app()->SESSION['userid']
with no
Yii::app()->session->open();
at login
Yii::app()->session->destroy();
at logout
I wanna know if dont do the open and destroy session is it worthy . Does Yii do it internally.
One more strange thing I dont know whats happening. In the same browser for a session I can login for multiple users .. this should not happen so.Is it that i am not using the open and destroy session methods .
public function actionLogout() { Yii::app()->user->logout(); Yii::app()->session->clear(); $this->redirect(Yii::app()->controller->module->returnLogoutUrl); }
Please let me know how do i figure this out
-
Tested over 10 yearsunset() ,destroy() ,clear() session should it be used in logout
-
Moyed Ansari over 10 yearsif you use yii auth, you need to call logout() method github.com/yiisoft/yii/blob/1.1.14/framework/web/auth/…
-
Tested over 10 yearsYii::app()->session->clear(); in action logout ........ In the same browser for a session I can login for multiple users .. this should not happen so.Is it that i am not using the open and destroy session methods ..... this is i wanna figoure out
-
Moyed Ansari over 10 yearstry Yii::app()->user->logout(true);
-
Jigar7521 almost 7 yearsWhat if i have one common server i.e localhost , and there is two directory like test1 and test2 and both of this having two yii frameworks installed and working in a separate way. In this case if you will change the value of Yii::app()->session['user_id'] then it will affect to both in case of same session variable. Have you any solution with this?