Welcome Guest, Not a member yet? Register   Sign In
set_cookie problem with expire time
#1

[eluser]Ornis[/eluser]
Hallo

I set a persistent cookie in a helper file which works perfectly:

Code:
$cookie = array(
        'name'   => 'PersistentCookie',
        'value'  => $value,
        'expire' => time() + 31 * 24 * 60 * 60,
        'domain' => '.mywebsite.ch',
        'path'   => '/',
        'prefix' => '');
$CI->input->set_cookie($cookie);

However, the cookie expires `At The End Of Session`, not at the requested time.

Thanks for your help.

Martin
#2

[eluser]ranjudsokomora[/eluser]
Hello Ornis,
Try setting a cookie using pure php.
Code:
setcookie("TestCookie", $value, time()+3600);  /* expire in 1 hour */

If this still doesn't work, let me know.
#3

[eluser]Aken[/eluser]
Two things:

1) CodeIgniter automatically adds in the current time() to the expiration. So do not add time() in yourself, only the number of seconds ahead of the current time when you'd like it to expire. So remove time() from your equation and that will help.

2) If you have set any of your cookie preferences in the application/config/config.php file to things BESIDES the default, but you set any of the above items in your array to the default, they will be overwritten to the items set in the config file.

For example, the following defaults are checked in the set_cookie function:
Code:
prefix: ''
domain: ''
path: '/'
secure: FALSE

If any of those items in your $cookie array are equal to those defaults, but they are NOT equal to the defaults in the config file, it'll take the value from your config file instead. So double check those, because it could be very easily overlooked.
#4

[eluser]Ornis[/eluser]
Thanks Aken. Your hint solved the problem.




Theme © iAndrew 2016 - Forum software by © MyBB