Laravel 5 Session variables not persisting after redirects Twitter OAuth

*爱你&永不变心* 提交于 2020-01-06 19:15:31

问题


Using Codebird, I request oauth token here

$reply = $cb->oauth_requestToken(array(
            'oauth_callback' => 'http://localhost/laravel/public/callback'
        ));
        print_r($reply);
        $cb->setToken($reply->oauth_token, $reply->oauth_token_secret);
        Session::put('oauth_token', $reply->oauth_token);
        Session::put('oauth_token_secret', $reply->oauth_token_secret);
        Session::put('oauth_verify', true);
        Session::save();
        $auth_url = $cb->oauth_authorize();
        header('Location: ' . $auth_url);
        die();

Variables are all correctly put into session here (as I can test this by putting a die() after the print)

Callback code from Twitter Authorisation

$verify = $_GET['oauth_verifier'];

    Session::put('oauth_token', $_GET['oauth_token'] );
    Session::put('oauth_verify', true);

    Session::save();
    var_dump(Session::all());
    header('Location: ' . "http://localhost/laravel/public/test?oauth_verifier=".$verify);
    die();

var_dump here does not show the session variables that were stored in the code segment above and after the redirect to localhost, session variables are empty.

Is there something I have missed out in Laravel (5)?


回答1:


Issue was in config/session

'driver' => env('SESSION_DRIVER', 'file')

env 'SESSION_DRIVER' was empty, changing the line to:

'driver' =>  'file'

Solves the problem and now session variables persist on redirects.



来源:https://stackoverflow.com/questions/30545235/laravel-5-session-variables-not-persisting-after-redirects-twitter-oauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!