title: Codeigniter 3.0.3 sessions are not persistent
body: <p>I am having very weird problem, The sessions in Codeigniter 3.0.3 are not saved for next request. Each time when a request is done, it creates a new session record and doesn't use it next time. </p>
  
  <p>The weird part of it is, it <strong>does work</strong> on <strong>HTTPS</strong> version of website, but not <strong>HTTP</strong>.</p>
  
  <p><em>The scenario:</em> On the login page of my website, I do an AJAX call (on this call I set some session variables and flashdatas). Once I get success message, I reload page to the profile page. </p>
  
  <p>This whole process don't work when I use HTTP, but HTTPS.</p>
  
  <p>Any help would be appreciated. </p>
  
  <p><strong>EDIT v1:</strong> Addition, even <strong>CSRF</strong> doesn't work over HTTP. I disable it to test the system. </p>
  
  <p><strong>EDIT v2:</strong> Code requested by @DFriend</p>
  
  <p><strong>config.php</strong></p>
  
  <pre><code>$config['sess_driver'] = 'database';
  $config['sess_cookie_name'] = 'jupiter';
  $config['sess_expiration'] = 0;
  $config['sess_save_path'] = "hkr_sessions"; 
  $config['sess_match_ip'] = TRUE;
  $config['sess_time_to_update'] = 300;
  $config['sess_regenerate_destroy'] = FALSE;
  
  $config['cookie_prefix']    = '';
  $config['cookie_domain']    = '.jupiter.rjv.me';
  $config['cookie_path']      = '/';
  $config['cookie_secure']    = TRUE; // PS: tried FALSE version as well, but no change. 
  $config['cookie_httponly'] = FALSE;
  </code></pre>
  
  <p><strong>User.php</strong> controller</p>
  
  <pre><code>public function login_required() {
    if (!$this-&gt;logged_in()) {
      $this-&gt;session-&gt;set_flashdata("login_error", "You have to be logged in to see this page.");
      $this-&gt;session-&gt;set_userdata('redirect_back', $this-&gt;agent-&gt;referrer());
      redirectt('/login');
    }
  }
  </code></pre>
  
  <p><strong>routes.php</strong></p>
  
  <pre><code>$route['login/required'] = 'user/login_required';
  </code></pre>
  
  <p>A simple method like this, when I browse to <code>http://domain.ltd/login/required</code> it redirects to <code>http://domain.ltd/login</code> with printing message like <em>"You have to be logged in to see this page."</em>. Once the user logins, it redirects user back to the page previously he/she was. </p>
  
  <p>In my case it does redirect to <code>/login</code> page, but doesn't print out flashdata message.</p>
  
  <p>Here is <strong>MY_Controller.php</strong></p>
  
  <pre><code>class MY_Controller extends CI_Controller {
    protected $logged_in = NULL;
    protected $is_ajax   = NULL;
    protected $user_id   = NULL;
  
    public function __construct() {
      parent::__construct();
  
      log_message("DEBUG", "session variables: " . print_r($this-&gt;session-&gt;all_userdata(), true));
  
      $this-&gt;logged_in = $this-&gt;session-&gt;userdata('logged_in');
      $this-&gt;is_ajax = $this-&gt;input-&gt;is_ajax_request();
      $this-&gt;user_id = $this-&gt;session-&gt;userdata('user_id');
    }
  }
  </code></pre>
  
  <p>As you see, I print out session variables on each request. </p>
  
  <p>Here is the output of the sessions over HTTP request:</p>
  
  <pre><code>DEBUG - 2016-01-03 07:17:27 --&gt; session variables: Array
  (
      [__ci_last_regenerate] =&gt; 1451805447
  )
  </code></pre>
  
  <p>Here is the output of the sessions over HTTPS request: </p>
  
  <pre><code>DEBUG - 2016-01-03 07:19:44 --&gt; session variables: Array
  (
      [__ci_last_regenerate] =&gt; 1451805564
      [redirect_back] =&gt; https://jupiter.rjv.me/book/1497-sefiller-viktor-mari-huqo
  )
  </code></pre>
  
  <p>I haven't changed any code, just tried on both requests, HTTP and HTTPS. The session outputs are different. One doesn't save, the other does. I hope this would help you to identify the problem.</p>