CodeIgniter如何保持会话数据,即使浏览器关闭? [英] How CodeIgniter keeps session data even when browser closes?

查看:103
本文介绍了CodeIgniter如何保持会话数据,即使浏览器关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道会话如何在CodeIgniter工作。当浏览器关闭时,会话是否不会自动破坏? CodeIgniter不会在浏览器上销毁会话默认关闭:

  $ config ['sess_expire_on_close'] = FALSE;我们可以设置会话到期时间:








  $ config ['sess_expiration'] = 7200; 

现在,例如,如果我将过期时间设置为0,不要自己毁灭:

  $ this-> session-> sess_destroy 

那么,CodeIgniter如何在特定时间内保留会话信息,即使浏览器关闭后? / p>

此外,如果使用此默认设置(不会使浏览器关闭的会话过期)保持用户登录几天是安全的吗? (例如,存储在会话'logged_in'=> TRUE

解决方案

p> CodeIgniter中的会话不使用默认的PHP $ _ SESSION 。它使用自己的cookie实现。这就是为什么当你关闭浏览器时它不会被销毁。你还可以在CodeIgniter中使用会话与数据库选项 $ config ['sess_use_database'] = TRUE; 和其他事情你会发现这里: http://codeigniter.com/user_guide/libraries/sessions.html


I wonder how does the session work in CodeIgniter. Isn't the session suppose to be automatically destried when the browser is closed? The CodeIgniter does not destroy the session on browser close by default:

$config['sess_expire_on_close'] = FALSE;

Instead we can set the session expire time:

$config['sess_expiration']      = 7200;

Now for example if I set the expiration time to 0, it will keep the session as long as I do not destroy by myself:

$this->session->sess_destroy();

So how does the CodeIgniter keeps the session information for specific time, even after the browser is closed?

Also, is it secure if use this default setting(of not expiring the session with browser close) to keep user login for few days? (eg. store in session 'logged_in' => TRUE )

解决方案

The session in CodeIgniter do not use the default PHP $_SESSION. It uses its own implementation with cookies. That's why it's not destroyed when you close your browser. You can also use session with database in CodeIgniter with the option $config['sess_use_database'] = TRUE; and other things you will find here : http://codeigniter.com/user_guide/libraries/sessions.html

这篇关于CodeIgniter如何保持会话数据,即使浏览器关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆