Cookie expires on session out in Codeigniter

。_饼干妹妹 提交于 2019-12-11 07:26:48

问题


I am setting a cookie in my codeigniter application using the following code. Working fine .. but cookie get expires on session out.. Please help

$cookie = array(
        'name'   => 'tvcUsername',
        'value'  => $email,
        'expire' => time()+86500,
        'domain' => 'http://localhost/tvc',
        'path'   => '/',
        'prefix' => '',

    );

    $this->input->set_cookie($cookie);

Thanks in advance


回答1:


Two things I can think of:

a) localhost is not a valid domain, so cookies won't be saved for all browsers. Create yourself a HOST for "my.dev.server" or "localhost.dev" and point to 127.0.0.1 (you may also need to configure apache to respond to that name - but try it first just changing the HOSTS file first)

b) In addition, your "domain" includes a scheme and a path - that might be causing problems? Set to "localhost.dev" (drop the "http://" and the "/tvc" parts - once you've moved away from localhost.




回答2:


The expiration is set in seconds, which will be added to the current time. Do not include the time, but rather only the number of seconds from now that you wish the cookie to be valid.

source: http://ellislab.com/codeigniter/user-guide/libraries/input.html



来源:https://stackoverflow.com/questions/10611261/cookie-expires-on-session-out-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!