title: codeigniter not retrieving session in another controller
body: <p>I'm totally stuck here, I created a controller login which it get, set rules and authentication with DB and at the end of code it set session.
  Also I have another controller dashboard which displays dashboard and also must use session to see if session is set, if true user can use the controller else redirect to login page. that's it 
  But I can't get session in dashboard, what should I do here?</p>
  
  <pre><code>&lt;?php
  defined('BASEPATH') OR exit('No direct script access allowed');
  
  class Login extends CI_Controller
  {
  
      /**
       * Login constructor.
       */
      public function __construct()
      {
          parent::__construct();
  
          //Load Form helper
          $this-&gt;load-&gt;helper('form');
  
          //Load form validation library
          $this-&gt;load-&gt;library('form_validation');
      }
  
      /**
       *Display Login page
       */
      public function index()
      {
  
          $title['title'] = 'Admin login';
          $this-&gt;load-&gt;view('login', $title);
      }
  
  
      /**
       *
       * Set rules for authentication
       *
       * @return bool
       */
      public function rules()
      {
  
          $rules = array(
              array(
                  'field' =&gt; 'username',
                  'label' =&gt; 'Username',
                  'rules' =&gt; 'trim|required|xss_clean'
              ),
              array(
                  'field' =&gt; 'password',
                  'label' =&gt; 'Password',
                  'rules' =&gt; 'trim|required|xss_clean'
              ),
              array(
                  'field' =&gt; 'remember',
                  'label' =&gt; 'Remember',
                  'rules' =&gt; 'trim|int|xss_clean'
              )
          );
  
          $this-&gt;form_validation-&gt;set_rules($rules);
  
          if ($this-&gt;form_validation-&gt;run() != FALSE) {
              $this-&gt;authentication();
          } else {
  
              $title['title'] = 'Admin login';
              $this-&gt;load-&gt;view('login', $title);
          }
      }
  
      /**
       * Check if user is exist
       */
      public function authentication()
      {
  
          $data = array(
              'username' =&gt; $this-&gt;input-&gt;post('username', true),
              'password' =&gt; $this-&gt;input-&gt;post('password', true)
          );
  
          $this-&gt;load-&gt;model('userData');
          if ($this-&gt;userData-&gt;getUserData($data) == FALSE) {
  
              $title['title'] = 'Admin login';
              $this-&gt;load-&gt;view('login', $title);
          } else {
  
              $this-&gt;set_session($data);
              redirect('dashboard/index');
          }
  
      }
  
      /**
       * @param $data username|password
       */
      public function set_session($data)
      {
  
          $session_data = array(
              'username' =&gt; $data['username'],
              'login' =&gt; true
          );
  
          $this-&gt;session-&gt;set_userdata('auth', $session_data);
      }
  
  }
  </code></pre>
  
  <p>and here is dashboard:</p>
  
  <pre><code>&lt;?php
  defined('BASEPATH') OR exit('No direct script access allowed');
  
  
  class Dashboard extends CI_Controller{
  
      public function __construct()
      {
          parent::__construct();
  
      }
  
      /**
       * Display dashboard 
       */
      public function index(){
  
  
          $array = $this-&gt;session-&gt;userdata('auth');
          $login = $array['login'];
  
          if ($login == true) {
              $title['title'] = 'Dashboard';
              $this-&gt;template-&gt;load('panel/dashboard', $title);
          }else{
              redirect('login/index');
          }     
      }
  }
  </code></pre>