Sessions in Yii

Tested picture Tested · Jan 7, 2014 · Viewed 41.1k times · Source

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

Answer

Moyed Ansari picture Moyed Ansari · Jan 7, 2014

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();