简体   繁体   English

重定向后 Laravel 5 会话消失

[英]Laravel 5 session disappearing after redirection

In laravel 5.7, session is getting disappeared after redirecting to another page.在 Laravel 5.7 中,会话在重定向到另一个页面后消失了。 I am working on an application in which I am pushing users to the payment gateway page before which I am storing the data in a session as per laravel documentation .我正在开发一个应用程序,在该应用程序中,我将用户推送到支付网关页面,然后根据 laravel文档将数据存储在会话中。 After coming back from the payment gateway when I try to retrieve that session it returns empty.从支付网关回来后,当我尝试检索该会话时,它返回空。 Can anyone please tell me how can I resolve this issue.任何人都可以告诉我如何解决这个问题。

My code is something like this我的代码是这样的

public function processPayment(Request $request)
 {
    //...........
    session()->put('order_checkout_data', [
        'gateway' => 'paypal',
        'data' => $paypalData
    ]);

    //$request->session()->save();  <!-- This i tried after reading some solution but didnt help

    //print_r(session('order_checkout_data')) <!-- I can see the session here

    $paypal = new PayPal();
    $response = $paypal->purchase($paypalData);

    if ($response->isRedirect()) {
        $response->redirect(); //This is where redireting to paypal
            }
}

public function handleGatewayResponse(Request $request){
    print_r(session('order_checkout_data')); //No data
}

I tried with session global function and facade as well , like these我也尝试过会话全局函数和外观,就像这些

Session::put('order_checkout_data', [
            'gateway' => 'paypal',
            'data' => $paypalData
        ])

and also并且

session(['order_checkout_data'=>[
            'gateway' => 'paypal',
            'data' => $paypalData
        ]])

But no value.但没有价值。 My env settings likes this我的环境设置喜欢这个

SESSION_DRIVER=file
SESSION_LIFETIME=360

I tried to go through some of the links with a similar problem but that didn't help.我试图浏览一些有类似问题的链接,但这没有帮助。 Here are the links that I have followed :以下是我遵循的链接:

When you use sessions, a SESSION_ID (or similar) cookie is sent to the browser to know what session is associated with each request.当您使用会话时,会向浏览器发送一个 SESSION_ID(或类似的)cookie,以了解与每个请求关联的会话。

Your handleGatewayResponse method is called after a request from a user (it's certainly your js script that issues the request but it's the same), and you store data in the session linked to this particular user.您的handleGatewayResponse方法在用户发出请求后调用(当然,发出请求的是您的 js 脚本,但它是相同的),并且您将数据存储在链接到该特定用户的会话中。

After PayPal finished its job, it does a request to a callback URL. PayPal 完成其工作后,它会向回调 URL 发出请求。 This request is done by PayPal but not by your user you stored the data for.此请求由 PayPal 完成,而不是由您为其存储数据的用户完成。 PayPal has no idea of the session cookie, so Laravel start a new empty session. PayPal 不知道会话 cookie,所以 Laravel 开始一个新的空会话。

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

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