简体   繁体   English

YII2 AuthClient onAuthSuccess会话未保存

[英]YII2 AuthClient onAuthSuccess session Not Saving

Hope someone could help me with this issue. 希望有人可以帮助我解决这个问题。

We are using AuthClient for Social Signup and Login. 我们正在使用AuthClient进行社交注册和登录。 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. 该功能在Windows XAMPP(PHP 5.6)上本地运行良好,但在服务器(Amazon Ec2 AMI,PHP 5.6)上,代码未保存会话数据。

public function onAuthSuccess($client)
{   
    //.... COMMENTED CODE
    $session = Yii::$app->session;

    //Store social info in session
    $session['socialClient'] = $_GET['authclient'];

    return;
}

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. 当我们尝试在以下Controller Action中访问上述功能中设置的会话数据时,永远不会保存会话数据。

Weirdly after hours of research, if we use the PHP standard header() and exit() then it all works, fine. 经过数小时的研究,很奇怪,如果我们使用PHP标准的header()exit()那么一切都很好。

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

I have tried all the combination, but still no luck. 我尝试了所有的组合,但还是没有运气。

eg return $this->redirect() 例如return $this->redirect()

I am not sure if its a PHP issue or something to do with YII2 session handling. 我不确定这是PHP问题还是与YII2会话处理有关。 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. 任何帮助都会有很大帮助。

Thanks 谢谢

Try using $session->open(); 尝试使用$ session-> open(); to open a session first before assigning some values. 在分配一些值之前先打开一个会话。

Therefore, your code should be like: 因此,您的代码应类似于:

    `public function onAuthSuccess($client)
{   

    $session = Yii::$app->session;
    $session->open();//Open session.
    //Store social info in session
    $session['socialClient'] = $_GET['authclient'];

    return;
}

You said onAuthSuccess() is an action right? 您说过onAuthSuccess()是一种操作对吗? If yes then please use actionOnAuthSuccess(). 如果是,请使用actionOnAuthSuccess()。 This might be the reason you are not getting the values in the session because this action was never found. 这可能是您未在会话中获取值的原因,因为从未发现此操作。

In their example: 在他们的示例中:

 public function successCallback($client)
 {
      $attributes = $client->getUserAttributes();
      // user login or signup comes here
 }

Your code: 您的代码:

//Store social info in session
$session['socialClient'] = $_GET['authclient'];

It's a callback function, you wouldn't get any parametes from $_GET. 这是一个回调函数,您不会从$ _GET获得任何参数。 You may use the variable '$client' to get some data. 您可以使用变量“ $ client”来获取一些数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM