Reputation: 65
I have this problem in my login system that after login if user closes the window/browser and then open that same page it will ask to login again. I want to keep user logged in until user logs out. I am using following code to login user
public function adminLogin()
{
$email = $this->input->post('email');
$password = md5($this->input->post('password'));
$user = $this->login_model->getUserDate($email,$password);
$user_data = array(
'user_id' => $user['user_id'],
'role' => $user['role'],
'logged_in' => true
);
$this->session->set_userdata($user_data);
redirect('admin-panel');
}
and this is config
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 172800;//48 hours
$config['sess_save_path'] = APPPATH . 'session';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
How can i achieve this, so that user doesn't have to login again when window/browser is closed and reopened.
Upvotes: 0
Views: 1419
Reputation: 13
I think that you should use cookies with timer.
<?php
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>
Upvotes: 1