Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

php - Sessions in Yii

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...