My Codeigniter's sessions used the default value
$config['cookie_domain'] = "";
But now I need to be able to use CodeIgniter's sessions from domain.com on
- subdomain1.domain.com
- subdomain2.domain.com
So I saw in the codeigniter manual that you can set
$config['cookie_domain'] = ".domain.com";
And the extra dot will make all the ci_sessions shared by the domain and subdomains. This works perfect!
However, it is impossible to log back in the system after changing cookie_domain
from ""
to ".domain.com"
unless I manually delete the cookie ci_session
in the chrome settings.
I can't ask all the users to delete their cookies so I need to find a way. I tried all of this:
delete_cookie('ci_session');
setcookie('ci_session', '', time()-3600);
$this->session->sess_destroy();
unset($this->session->userdata);
$this->session->unset_userdata( <array with all the session keys> )
foreach ($_COOKIE as $key=>$cookie)
setcookie($key, '', time() - 9999999);
Some useful info maybe, sess_expiration
is set to 2 weeks, this is why I tried a huge number in the setcookie function:
$config['sess_expiration'] = 1209600; // 2 weeks
Also, after all these commands to make the cookie expired. Chrome still says that the ci_session cookie expires in 2 weeks. It's as if it was completely oblivious to the function setcookie