CodeIgniter Forums
Chrome Cookie Issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Chrome Cookie Issue (/thread-25514.html)



Chrome Cookie Issue - El Forum - 12-14-2009

[eluser]dave177[/eluser]
Before Thanksgiving I had sessions/cookies working successfully in Chrome. However, now when I try to set a session in chrome it doesn't work... I don't see a cookie being created. However the cookie is created in firefox. I haven't changed any code which leads be to believe that some change was made within Chrome (a Google update perhaps?) that caused this to fail. The problem isn't isolated to my machine. Chrome is set to allow all cookies.

The relevant section of config.php is below. Has anyone else had this problem?

/*
|--------------------------------------------------------------------------
| Session Variables
|--------------------------------------------------------------------------
|
| 'session_cookie_name' = the name you want for the cookie
| 'encrypt_sess_cookie' = TRUE/FALSE (boolean). Whether to encrypt the cookie
| 'session_expiration' = the number of SECONDS you want the session to last.
| by default sessions last 7200 seconds (two hours). Set to zero for no expiration.
| 'time_to_update' = how many seconds between CI refreshing Session Information
|
*/
$config['sess_cookie_name'] = 'test';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update'] = 300;

/*
|--------------------------------------------------------------------------
| Cookie Related Variables
|--------------------------------------------------------------------------
|
| 'cookie_prefix' = Set a prefix if you need to avoid collisions
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
| 'cookie_path' = Typically will be a forward slash
|
*/
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "";
$config['cookie_path'] = "/";


Chrome Cookie Issue - El Forum - 12-14-2009

[eluser]dave177[/eluser]
Some more information:

I'm using CI 1.7.2
The problem also happens in Safari
The only difference I see in logging for chrome/safari vs firefox is that chrome/safari logs have this "A session cookie was not found"


Chrome Cookie Issue - El Forum - 12-14-2009

[eluser]dave177[/eluser]
never mind, the time on the server got reset. problem solved.


Chrome Cookie Issue - El Forum - 09-03-2010

[eluser]bimtee[/eluser]
change $config['sess_expiration'] = 7200; to $config['sess_expiration'] = 86400;


Chrome Cookie Issue - El Forum - 09-03-2010

[eluser]bimtee[/eluser]
right so after some playing with the core files. I realized that

if ( ! $this->sess_read())
{
$this->sess_create();
}

in the Session.php constructor was always calling $this->sess_create(); no matter what. This was because

$this->sess_read() always returned false because the cookie it was looking for was being created and destroyed

.
.
.
// Fetch the cookie
$session = $this->CI->input->cookie($this->sess_cookie_name);

// No cookie? Goodbye cruel world!...
if ($session === FALSE)
{
log_message('debug', 'A session cookie was not found.');
return FALSE;
}

On SHARED hosting some of us live in countries where the time differs so 12:00PM here is 11:00PM is USA where my site is hosted. I think chrome uses time to help validate the legitimacy of cookies there the default 7200 = i think is causing the cookie to be destroyed

at some point sess_create will call the set _set_cookie function. which contains php native setcookie function with the said 7200 is created and destroyed by Chrome because of the time difference on your PC and your website host.

INCREASE that 7200 to a day or two!

SET THE DOMAIN AS WELL!