When I use redirect function after auto login this error occur:
session_regenerate_id(): Session object destruction failed
Can anyone hep me?
<?php
public function actionRegister()
{
$model = new UserProfileForm;
$this->performAjaxValidation($model,'userProfile-form');
if(isset($_POST['UserProfileForm']))
{
$model->attributes = $_POST['UserProfileForm'];
if ($model->save())
{
$u = new LoginForm;
$u->username = $model->username;
$u->password = $model->password;
$u->login();
$this->redirect(Yii::app()->user->returnUrl);
}
}
$this->render('register',array('model'=>$model,));
}
?>
The following works.
if($model->save()){
$identity=new UserIdentity($model->username,$model->password);
$identity->authenticate();
Yii::app()->user->login($identity);
$this->redirect(Yii::app()->user->returnUrl);
}
PS: $model->save()
runs $model->validate()
so you are repeating yourself
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.