Codeigniter cookie expiration problem

I have a problem with the cookie, the expiration date of my cookie is always set to "At the end of the session", which I do not want. I worked a little, and he suggested setting the time for the expiration of time () + 60 * 60 * 24 * 30, which I did.

 //Create basket cookie
            $cookie = array(
                'name'   => 'basket_id',
                'value'  => $basket_id,
                'expire' => time()+60*60*24*30,
                'domain' => 'domain',
                'path'   => '/',
                'prefix' => '',
            );
            set_cookie($cookie);

I really wondered if this could be before the Codeignter parameter, but my ci_session cookie has a normal expiration date. Thu. 09 Jun. 2011 10:39:02 GMT

This is what I get when I view a cookie:

 Name   basket_id
 Value  28
 Host   .host
 Path   /
 Secure No
 Expires    At End Of Session

And here is an example of an array that I pass to the cookie.

Array ( [name] => basket_id [value] => 30 [expire] => 1310202067 [domain] => host [path] => / [prefix] => ) 
+3
source share
3 answers

config.php. CI cookie:

/** Session Variables
 ---------------------------------------
| '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.
|
*/

$config['sess_expiration']      = 7200;
+4

​​. (), , , ().

expire, 0, .

, :

            $cookie = array(
            'name'   => 'basket_id',
            'value'  => $basket_id,
            'expire' => 86400*30,
            'domain' => 'domain',
            'path'   => '/',
            'prefix' => '',
        );
+4

You can add parameters

$config['cookie_lifetime']  = 1800

in config.php, the reason you can find in the /Sessions/Session.php libraries below.

$expiration = config_item('sess_expiration');

if (isset($params['cookie_lifetime']))
{
    $params['cookie_lifetime'] = (int) $params['cookie_lifetime'];
}
else
{
    $params['cookie_lifetime'] = (!isset($expiration) && config_item('sess_expire_on_close'))
        ? 0 : (int) $expiration;
}
0
source

All Articles