Set Session Expiration Time Manually-CodeIgniter

后端 未结 9 900
粉色の甜心
粉色の甜心 2021-01-01 10:23

How can I set session expiration time dynamically in codeigniter?

For example, if a user logs in and has the role of admin, the expiration time should b

相关标签:
9条回答
  • 2021-01-01 11:01
    $data = array(
    'username' => $this->input->post('username'),
    'ADMIN_is_logged_in' => true
    );
    
    $this->session->sess_expiration = '14400';// expires in 4 hours
    $this->session->set_userdata($data);// set session
    
    0 讨论(0)
  • 2021-01-01 11:03

    You can handle this with a custom controller. When a user logs in, set a session variable with the time of login. Create custom controller that contains a function in the constructor to check if the user is not admin user and if the timeout has expired. If it has, call $this->session->destroy(); Now, make all your controllers extend that controller instead of the CI base controller.

    0 讨论(0)
  • 2021-01-01 11:08

    Session will expire in 10 seconds

    $config['sess_expiration']= 10;
    

    Session will not expire

    $config['sess_expiration']= 0;
    
    0 讨论(0)
提交回复
热议问题