title: Codeigniter: Can't get session variable value from one controller to another
body: <p>I have included session in autoload, and its working on all other places.
  I'm having problem in retrieving session variable it return null result. While in the controller where i have set the session there it's working fine.<br>
  Here is the code where i'm setting it in else condition:</p>
  
  <pre><code>class Controller_catagory extends CI_Controller
  {
  
      public function __construct() 
      {
          parent::__construct();
  
          $this-&gt;load-&gt;model('generic_model');
          $this-&gt;load-&gt;model('backend/model_post');
          $this-&gt;load-&gt;model('backend/model_permissions');
      }
  
      public function index($param1='',$param2='') 
       {
          $id=$this-&gt;generic_model-&gt;getAllRecords('dramas',array(
              'drama_slug' =&gt; $param2 ),'drama_id','DESC');
          // print_r($id);
          if (!empty($id)) 
          {
              foreach ($id as $key) 
              {
                  $id = $key['drama_id'];
              }
          }
          $data;
  
          if (!empty($param1) &amp;&amp; empty($param2)) 
          {
              $data["page"]    = 'frontend/includes/view_alldramas';
  
  
              $id = $this-&gt;generic_model-&gt;getAllRecords('channel',array('channel_slug' =&gt; $param1 ),'channel_id','DESC');
  
              if (!empty($id)) 
              {
                  foreach ($id as $key) 
                  {
                      $id = $key['channel_id'];
                      $ch_slug= $data['ch_slug'] = $key['channel_slug'];
                      $this-&gt;session-&gt;set_userdata('ch_slug',$ch_slug);
                  }
              }
  
              $this-&gt;session-&gt;set_userdata('channel_capture',$id);
  
              $data['dramas_pagination'] = $this-&gt;model_post-&gt;get_specific_channel_pagination(0,12,$id);
              $data["get_dramas"]=$this-&gt;model_post-&gt;get_all_dramas();
  
              $data['channels'] = $this-&gt;generic_model-&gt;getAllRecords('dramas', array('channel_fk' =&gt; $id ),'drama_id','DESC');
          }
          else
          {
              // The id is printing right result
              echo $id;
  
              // Here i'm setting session, if i retrieve here its working
              $this-&gt;session-&gt;set_userdata('drama_episode',$id);
  
              $data['episodes_pagination'] = $this-&gt;model_post-&gt;get_specific_post_pagination(0,12,$id);
              $data["get_episodes"]=$this-&gt;model_post-&gt;get_all_dramas();
              $data['dramas'] = $this-&gt;generic_model-&gt;getAllRecords('post',$arr = array(
              'dramas_fk' =&gt; $id ),'id','DESC');
              $data["page"]    = 'frontend/includes/view_allposts';
  
          }
  
          $data['title']   = 'GLOBAL VIDEOS';
          $data['heading'] = 'Dramas List';
          $data["top"]     = 'frontend/includes/top_home';
  
  
          $this-&gt;load-&gt;view('frontend/index',$data);
      }
    }
  
  }
  </code></pre>
  
  <p>Now here is another class where i'm trying to get the value of set session but its not retrieving the data and i'm getting empty record.<br></p>
  
  <blockquote>
    <p>Note: i am doing the same thing with 'channel_capture' and i'm successfully getting its value</p>
  </blockquote>
  
  <pre><code>class Home extends CI_Controller {
  
   public function __construct() 
  {
      $data = array();
      parent::__construct();
  
  
      $this-&gt;load-&gt;model('backend/model_post');
      $this-&gt;load-&gt;model('generic_model');
  }
  public function ajax_posts()
  {
      $start= $_GET['start'];
  
      // it gives empty result here don't know why
      $id = $this-&gt;session-&gt;userdata('drama_episode');
  
      //prints nothing
       echo "This key: ".$id;
  
      $post_pagination=$this-&gt;model_post-&gt;get_specific_post_pagination($start, 12, $id);
      var_dump($post_pagination);
      $str='';
      $base_url=base_url();
  
      if (empty($post_pagination))
      { 
          return false;
      }
  
      foreach($post_pagination as $post)
      {
  
          $str.=          '&lt;div class="col-lg-3 col-sm-6 col-md-4 epi_height" &gt;';
          $str.=              '&lt;a href='.$base_url.$post['slug'].'&gt;';
          $str.=              '&lt;img class="img-responsive" src='.$base_url.$post['thumbnail'].' alt="recent dramas" /&gt;';
          $str.=              $post['title'];
          $str.=              '&lt;/a&gt;';
          $str.=         '&lt;/div&gt;';    
  
      }
          echo $str; 
     }
  }
  </code></pre>