Session after callback is destroyed in codeigniter

php

#1

Dear community,

I am using Abraham\TwitterOAuth php library for Twitter API .I am working on Codeigniter framework. I am trying to get user followers.when user authorize the callback url is called It is ok till then but redirected to callback function session variable stored gets destroyed automatically. I am highly troubled and stuck here for 3 days. Please help would be highlt appreciated. I have created a library on top of Abraham\twitterOAuth.This is the library I made.

//application/libraries
        class Twitter  {

      public  function __construct() {
            $ci =& get_instance();

           if($this->ci->session->userdata('tw_access_token'))    $access_token =  $this->ci->session->userdata('tw_access_token'); else    $access_token = false;
            if ( $access_token && isset($access_token['oauth_token']) && isset($access_token['oauth_token_secret']) ) {
                
                $this->tw = new TwitterOAuth(TWITTER_APP_KEY, TWITTER_APP_SECRET,$access_token['oauth_token'], $access_token['oauth_token_secret']);
                $this->tw_access_token = $access_token;
                $this->tw_user_id = ( isset($access_token['user_id']) ? $access_token['user_id'] : null);
                $this->tw_user_name = ( isset($access_token['screen_name']) ? $access_token['screen_name'] : null);

            
            } else {
                $request_token = $this->ci->session->userdata('tw_request_token');
                if ( $request_token && isset($request_token['oauth_token']) && isset($request_token['oauth_token_secret']) ) {
                     $this->tw= new TwitterOAuth(TWITTER_APP_KEY, TWITTER_APP_SECRET, $request_token['oauth_token'], $request_token['oauth_token_secret']);
                    $this->tw_request_token = $request_token;
                } else {
                       $this->tw= new TwitterOAuth(TWITTER_APP_KEY, TWITTER_APP_SECRET);
                }
            }
            // $this->tw_config = $config;
            $this->tw_status=isset($_SESSION['tw_status'])?$_SESSION['tw_status']:false;
            
            $this->host = 'https://api.twitter.com/1.1/'; // Use API v1.1

        }

        public $tw_user_id = null;
        public $tw_user_name = null;
        public $tw_user_info = null;
      
        public $tw_request_token = null;
        public $tw_access_token = null;
        public $tw_status = null;
        public $tw;

        /**
         * to get login url
         */
        public function getLoginUrl($callback_url = '') {

             if ($callback_url == '') {
                $callback_url =TWITTER_APP_REDIRECT_URI;
            }

            $request_token =$this->tw->oauth('oauth/request_token', array('oauth_callback' => $callback_url));
            $token = $request_token['oauth_token'];
        //this session is set here which gets destroyed
  `$_SESSION['tw_request_token']= $request_token;`
            return ( $this->tw->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token'])) );
            
        }
        
        /**
         * 3. Requests permanent access token after callback
         */
        public function twprocess_callback() {
//no session is available
print_r($_SESSION];
             $returned_request_token = $this->input->get('oauth_token');
            $request_token = $this->tw_request_token;
            if ($returned_request_token) {
                if ( $request_token['oauth_token'] != $returned_request_token) {
                    // echo 'The oauth_token is old, deleting it and returning false';
                 $this->session->unset_userdata('tw_request_token');
                    // unset($_SESSION['tw_request_token']);
                    $this->tw_request_token = null;
                    $this->tw_status = 'old_token';
                    $this->session->set_userdata('tw_status', 'old_token');
                     // $_SESSION['tw_status']= $old_token;
                    return false;

                } else {
                    // echo 'Request access tokens from twitter';
                    $access_token = $this->tw->getAccessToken($this->input->get('oauth_verifier'));

                   
                        $this->tw_access_token = $access_token;
                        $this->tw_user_id = $access_token['user_id'];
                        $this->tw_user_name = $access_token['screen_name'];
                        $this->session->set_userdata('tw_access_token', $access_token);
                       
                        $this->session->unset_userdata('tw_request_token');
                        // unset($_SESSION['tw_request_token']);
                            return true;
                
                }
            } else return false;
        }

Now I call function get getLoginUrl() to get url and when user clicks goes to a callback function.But when i call function
`

  //call back function redirected by app`
            public function signup_twitter(){
                     $this->load->library('Twitter');
                     print_r($this->session->userdata);
                 $ok=  $this->twitter->twprocess_callback();
            }

The session in function signup_twitter ans in twprocess_callback gets destroyed .
Please let me know if I am wrong or any thing is missing