Laravel 5会话变量在重定向Twitter OAuth后不持久 [英] Laravel 5 Session variables not persisting after redirects Twitter OAuth

查看:99
本文介绍了Laravel 5会话变量在重定向Twitter OAuth后不持久的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Codebird,我在这里请求oauth令牌

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();

所有变量都正确地放在了会话中(因为我可以通过在打印后放置die()来测试它)

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

Twitter授权的回叫代码

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不显示存储在上方代码段中的会话变量,并且在重定向到localhost之后,会话变量为空.

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.

在Laravel(5)中我错过了什么吗?

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

推荐答案

问题在配置/会话中

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

env'SESSION_DRIVER'为空,将行更改为:

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

'driver' =>  'file'

解决了这个问题,现在会话变量在重定向中仍然存在.

Solves the problem and now session variables persist on redirects.

这篇关于Laravel 5会话变量在重定向Twitter OAuth后不持久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆