title: Codeigniter redirect to login page if session already expires
body: <p>I am new to codeigniter framework and I don't really get how does the built-in session works. What I want is that when the session expires the user will be redirected to login page. I checked the answers in google and other stackoverflow questions and tried every code in their but it does not work. In the native php session I only need to specify that if the session expires in the given time then redirect but when I applied it in codeigniter it does not work. I don't know also how to retrieve the session expiration value in config to compare it to the current time accumulated by the user during his/her logged session. Please help....</p>
  
  <p>This is in function in controller</p>
  
  <pre><code>public function check_session()
  {
      $logged_in = $this-&gt;session-&gt;userdata('logged_in');
  
      if(!$logged_in)
      {
          $this-&gt;logout();
      }
  }
  </code></pre>
  
  <p>And this is the ajax:</p>
  
  <pre><code>setInterval(function(){
  $.ajax({
      type: 'POST',
      url: "&lt;?php echo site_url('tms/check_session');?&gt;",
      success: function(data){
          console.log(data);
      }
  });
  },300);
  </code></pre>