Welcome Guest, Not a member yet? Register   Sign In
Checking login sessions
#1

[eluser]Carl_A[/eluser]
Hi,
Im new to Codeigniter.
Im making a user login page, and i wanted to check for inactivity

Forexample, I create a new session using the session class when the user has properly logged in

Code:
class User extends Controller{
  
   function User()
    {
        parent::Controller();
        $this->load->helper('form');
        $this->load->helper('url');
        
    }
   function index()
   {
       if($this->session->userdata('logged_in')==TRUE)
       {
           $this->load->view('main_page');
       }
       else
           $this->load->view('login_page');
   }  
    
    function login()
    {
    $username = $this->input->post('Username');    
    $password  = $this->input->post('Pass');
    
    $this->db->where('Username',   $username);
    $this->db->where('Pass', $password);
    $query =$this->db->get('system_userdetails');
    
    if ($query->num_rows() > 0)
        {
           foreach ($query->result() as $row)
           {
              echo $row->ID;
              echo $row->EmailAddr;
              echo $this->session->userdata('session_id');
              $newdata = array(
                   'username'  => $row->Username,
                   'email'     => $row->EmailAddr,
                   'logged_in' => TRUE
               );
              
              $this->session->set_userdata($newdata);
           }
           redirect('User/index');
        }
    else
        {
           $this->load->view('login_page');
          
        }
      
      
    }  
  }

This works fine to login, but now i want to check if theres been no page load for say 10 mins, the session should get destroyed, and the user would have to re-login, but as long as the user stays active, the session continues..

How can i achieve that? I tried the Benchmark Class, however it seems to not work when the functions/controllers switch. (i.e I cant mark the starting point in my login function, and mark an ending point in another controller.. and check the time.)
When i echo'ed the value of time elapsed, if just gave me a blank page.

Please Help.

Thanks in advance
#2

[eluser]Doosje[/eluser]
In the config you can specify how long the session should be alive.
#3

[eluser]Carl_A[/eluser]
I dont want a predefined time for it to live..
I need to check for inactivity of the user. If he's inactive, it deletes the session, if hes active, the session stays.




Theme © iAndrew 2016 - Forum software by © MyBB