AuthClient onAuthSuccess Session Not Saving

Hi Guys,

Hope someone could help with this issue.

We are using AuthClient for Social Signup and Login. Feature is working fine locally on Windows XAMPP (PHP 5.6) but on the server (Amazon Ec2 AMI, PHP 5.6), code is not saving session data.

public function onAuthSuccess($client)



$session = Yii::$app->session;

//Store social info in session

$session['socialClient'] = $_GET['authclient'];



When we are trying to access the session data set in the above function in the following Controller Action, the session data is never saved.

Weirdly after hours of research, if we use the PHP standard header() and exit() then it all works, fine.

header("Location: " . $authObj->getSuccessUrl());


I have tried all the combination, but still no luck.

e.g. return $this->redirect()

I am not sure if its a PHP issue or something to do with YII2 session handling. There are few other screens, where I believe the session is not saving as client has logged few bugs recently related to data loss, while the code logic is fine and works locally.

Any help would be of great help.


I remember that I had similar issue, and I think it is not related with Yii Framework. I was working with oAuth Login (it was pure PHP project without any framework) my session were not saved properly, but I solved it by using sleep() function. After statement $session[‘socialClient’] = $_GET[‘authclient’]; add sleep(3); function that will wait 3 seconds before program flow hits return; statement.

Here is full code:

//Store social info in session

$session['socialClient'] = $_GET['authclient'];



Let me know if this is working.

Thanks mate, will try it now.

DIDN’t work. Just checked locally and same behavior. Just redirects and session is not saved.

Check whether the folder where sessions are saved is writable.

1.) Check where sessions are saved (session_save_path())

2.) Then check whether this folder has an writing rights

That’s definitely working as other session related information does gets saved and this piece of functionality we are implementing is post login, so user is logged in and the info is stored in session.

So I doubt its related to session_save_path() and write permission issue.

Having a feeling that session is not starting.