For my RSAuth Library I need that session cookies are deleted on Browser exit, so I need that the cookie expiration is null.
In the Session Library and config.php you only can configure some expiration time, or unlimited time (really add 2 years). So I mod the session library adding another possibility, if I set $config[‘sess_expiration’] = -1; (negative seconds) the session cookie is created with null parameter in expiration time (the session cookie expire on browser exit). I only change one line in the Session Library in the function sess_write line 278:
function sess_write()
{
$cookie_data = serialize($this->userdata);
if ($this->encryption == TRUE)
{
$cookie_data = $this->CI->encrypt->encode($cookie_data);
}
setcookie(
$this->sess_cookie,
$cookie_data,
/**HERE**/ ($this->CI->config->item('sess_expiration') < 0)?null:($this->sess_length + time()), /***HERE***/
$this->CI->config->item('cookie_path'),
$this->CI->config->item('cookie_domain'),
0
);
}
I suggest change the session library base to support “non-persistent” cookies. I would suggest…
1. Another config option: $config[‘is_persistent’] = FALSE / TRUE;
2. In session library constructor ...
$this->is_persistent = $this->CI->config->item(‘is_persistent’);
3. sess_write function ...
setcookie(
$this->sess_cookie,
$cookie_data,
/**HERE**/ ($this->is_persistent)?($this->sess_length + time()):null, /***HERE***/
$this->CI->config->item('cookie_path'),
$this->CI->config->item('cookie_domain'),
0
);
¿Another solutions?
