I'm using CodeIgniter to develop a project that involves a restricted area.
I am using session to store the data of the user that is logged in.
I need to close this browser when I close the browser, remembering that I am using CodeIgniter version 3.1.6 sessions.
Example of how I created the sessions:
$this->session->set_userdata('associated_hash', $userData[0]->hash);
How do I read the session:
public function index() {
if (!isset($this->session->associated_hash) || empty($this->session->associated_hash)) {
redirect('login');
}
...
}
How do I delete the session when I clicked the button:
$this->session->unset_userdata('associated_hash');
My configuration in config.php:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
Edit with check in builder:
public function __construct() {
parent::__construct();
if (!isset($this->session->associated_hash) || empty($this->session->associated_hash)) {
redirect('login');
}
}