title: php - Session are lost after redirect in CodeIgniter 3
body: <p>I would like to have some help in CodeIgniter 3. Every time I login and redirect to the index page, session is lost.</p>
  
  <p>Here is my code:</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>&lt;?php
  defined('BASEPATH') OR exit('No direct script access allowed');
  
  class Secretariat extends CI_Controller {
      public function __construct(){
          parent::__construct();
          $this-&gt;load-&gt;helper(array('form', 'url'));
          $this-&gt;load-&gt;model('SecretariatModel');
          $this-&gt;load-&gt;model('IndiRegModel');
          $this-&gt;load-&gt;model('RoomModel');
          $this-&gt;load-&gt;model('BuildingModel');
          $this-&gt;load-&gt;model('BilletModel');
          $this-&gt;load-&gt;model('BatchRegModel');
          $this-&gt;load-&gt;library('form_validation');
          $this-&gt;load-&gt;library('session');
      }
  
      public function secretariatLogin(){
  
          if ($this-&gt;session-&gt;isSecretariat){
              redirect('secretariat/index', $data);
  
  
          } else{
  
              $data['title'] = 'PACSA - Philippine Association of Campus Student Adviser';
  
              $this-&gt;load-&gt;view('include/toppage', $data);
              $this-&gt;load-&gt;view('include/defaultnavbar', $data);
              $this-&gt;load-&gt;view('pacsa/slider');
              $this-&gt;load-&gt;view('secretariat/secretariatLogin', $data);
              $this-&gt;load-&gt;view('include/bottompage');
  
         }
  
      }
  
      public function signin(){
          $secretariat = array(
              'sec_email' =&gt; $this-&gt;input-&gt;post('sec_email'),
              'sec_password' =&gt; sha1($this-&gt;input-&gt;post('sec_password'))
          );
  
          $user = $this-&gt;SecretariatModel-&gt;getSecretariat($secretariat);
          //print_r($user-&gt;name);die();
  
          if(!$user == null){
  
              $newdata = array(
                  'sec_id' =&gt; $user-&gt;sec_id,
                  'sec_name'  =&gt; $user-&gt;sec_name,
                  'sec_lastname' =&gt; $user-&gt;sec_lastname,
                  'sec_email' =&gt; $user-&gt;sec_email,
                  'sec_password' =&gt; $user-&gt;sec_password,
                  'sec_status' =&gt; $user-&gt;sec_status,
                  'sec_address' =&gt; $user-&gt;sec_address,
                  'logged_in' =&gt; TRUE,
                  'isSecretariat' =&gt; TRUE
              );
  
              $this-&gt;session-&gt;set_userdata($newdata);            
              redirect('secretariat/index');
          } else {
              $data['title'] = 'PACSA - Philippine Association of Campus Student Adviser';
              $data['message'] = 'Invalid email or password';
  
              $this-&gt;load-&gt;view('include/toppage', $data);
              $this-&gt;load-&gt;view('include/defaultnavbar', $data);
              $this-&gt;load-&gt;view('pacsa/slider');
              $this-&gt;load-&gt;view('secretariat/secretariatLogin', $data);
              $this-&gt;load-&gt;view('include/bottompage');
          }
      }    
  
      public function index(){
          $data['title'] = 'PACSA - Philippine Association of Campus Student Adviser';
          $id = $this-&gt;session-&gt;sec_id;
          var_dump($id);
          echo die();
  
          $this-&gt;load-&gt;view('include/toppage', $data);
          $this-&gt;load-&gt;view('include/secretariatnavbar', $data);
          $this-&gt;load-&gt;view('pacsa/slider');
          $this-&gt;load-&gt;view('secretariat/index', $data);
          $this-&gt;load-&gt;view('include/bottompage');
      }
  }
  </code></pre>
  
  <p>So after redirecting to the index page, I want to verify if there is a session involved. I tried to echo the id and the name of the user but I get a null value.</p>