title: CodeIgniter automatic logout user
body: <p>I am using the code below for automatic logout after 1 minute of inactivity. Now I have to use this code in CodeIgniter. I researched on google but did not found any solutions to my question. Even I checked on SO but not able to understand.</p>
  
  <p>1) I just need a help that where should I added auto logout code? </p>
  
  <p>2) How do I modify this code in CodeIgniter?</p>
  
  <p>3) Should I add this code in the controller?</p>
  
  <p>4) Should I update the login time every time till user in the system?</p>
  
  <p>Sorry for the lots of question, I am learning the Codeigniter Framework.</p>
  
  <pre><code>&lt;?php
  //on pageload
  session_start();
  $idletime=60;//after 60 seconds the user gets logged out
  if (time()-$_SESSION['timestamp']&gt;$idletime){
      session_destroy();
      session_unset();
  }else{
      $_SESSION['timestamp']=time();
  }
  //on session creation
  $_SESSION['timestamp']=time();
  </code></pre>
  
  <p>I am adding the login time into the database while user login.</p>
  
  <pre><code> $data_login= array('emp_id' =&gt;$result-&gt;id ,'login_time' =&gt;date("Y-m-d H:i:s", STRTOTIME(date('h:i:sa'))));
   $this-&gt;db-&gt;insert('tbl_current_login',$data_login);
   $last_id=$this-&gt;db-&gt;insert_id();
   if (!empty($last_id)) {
   $active_user_session = array('id' =&gt;$last_id,'access_role'=&gt;$result-&gt;access_role);
   $this-&gt;session-&gt;set_userdata('active_user_session',$active_user_session);
   return $result;
  </code></pre>
  
  <p>Let me know if need more explanation.</p>