简体   繁体   English

重定向后Codeigniter失去会话

[英]Codeigniter loses session after redirect

I am using Abraham Williams twitter api in order to log in the user. 我正在使用Abraham Williams twitter api来登录用户。 During step one I store the temporary oauth_token and oauth_token _secret in the session. 在第一步中,我将临时oauth_token和oauth_token _secret存储在会话中。 After the user is redirected to my page after the sign in process the session data stored previously are lost. 登录过程之后,将用户重定向到我的页面后,先前存储的会话数据将丢失。 How can I solve this ? 我该如何解决?

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');
    }

}

Of course you verified you config file in Session section, but: 当然,您已在“会话”部分中验证了配置文件,但是:

  1. Already you tried it in other PC? 您已经在其他PC上尝试过吗?
  2. Tried DB Sessions or the inverse? 尝试过数据库会话还是相反的?
  3. Made you simple tests excluding you case (twitter oauth class) 让您进行简单的测试(不包括案例)(twitter oauth类)
  4. In somehow, maybe the code are replacing the vars, try log the informations in many parts of the code, to see if it as overwrote in the life of the process 以某种方式,也许代码正在替换var,请尝试在代码的许多部分中记录信息,以查看它是否在整个过程中被覆盖

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

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