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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With