Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter在重定向后丢失会话_Php_Api_Codeigniter_Session_Twitter - Fatal编程技术网

Php Codeigniter在重定向后丢失会话

Php Codeigniter在重定向后丢失会话,php,api,codeigniter,session,twitter,Php,Api,Codeigniter,Session,Twitter,我使用Abraham Williams twitter api来登录用户。在第一步中,我将临时oauth_令牌和oauth_令牌秘密存储在会话中。在登录过程后,用户被重定向到我的页面后,先前存储的会话数据将丢失。我怎样才能解决这个问题 function oauth() { //Build TwitterOAuth object with client credentials $connection = new TwitterOAuth($this->consumer_key

我使用Abraham Williams twitter api来登录用户。在第一步中,我将临时oauth_令牌和oauth_令牌秘密存储在会话中。在登录过程后,用户被重定向到我的页面后,先前存储的会话数据将丢失。我怎样才能解决这个问题

function oauth()
{
    //Build TwitterOAuth object with client credentials
    $connection = new TwitterOAuth($this->consumer_key, $this->consumer_secret);

    //Get temporary credentials
    $request_token = $connection->getRequestToken($this->callback);

    //Save temporary credentials to session

    $session_data = array(
        'oauth_token'       => $request_token['oauth_token'],
        'oauth_token_secret'=> $request_token['oauth_token_secret'],
    );

    $this->session->set_userdata($session_data);


    //If last connection failed don't display authorization link.
    switch ($connection->http_code)
    {
        case 200:
            $url = $connection->getAuthorizeURL($request_token['oauth_token'], TRUE);
            header('Location: ' . $url);
            break;

        default:
            echo 'Could not connect to Twitter. Refresh the page or try again later.';
    }

}

function callback()//callback after user signs in with twitter
{

    $connection = new TwitterOAuth($this->consumer_key, 
                                   $this->consumer_secret,
                                   $this->session->userdata("oauth_token"),
                                   $this->session->userdata("oauth_token_secret"));

    $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);

    $this->session->set_userdata('access_token', $access_token);

    //Remove no longer needed request tokens
    $this->session->unset_userdata('oauth_token');
    $this->session->unset_userdata('oauth_token_secret');

    //If HTTP response is 200 continue otherwise send to connect page to retry
    if (200 == $connection->http_code)
    {
        $this->session->set_userdata('twitter_log_in', TRUE);
        redirect('/main/', 'refresh');
    }

}

当然,您已经在会话部分验证了配置文件,但是:

  • 你已经在其他电脑上试过了吗
  • 尝试DB会话还是相反
  • 使您能够进行简单的测试,不包括您的案例(TwitterOAuth类)
  • 在某种程度上,可能代码正在替换变量,尝试将信息记录在代码的许多部分中,以查看它是否在流程生命周期中被过度编写

  • 按其他区域检查问题,因为在5月份的情况下,我成功地获得了会话值。您说“以前存储的会话数据丢失”,是否在数据库中创建了新的会话记录?假设您使用DB会话。您使用的是什么web浏览器?你在WebKit、FireFox和IE中测试过吗?哪一个给你带来了麻烦?我有一个类似的问题,也许你会发现一些线索:WebKit中的Rails会话和OAuth,缺少会话数据,但在FireFox中工作?