防止破坏会话的CodeIgniter

时间:2014-02-24 19:02:03

标签: php codeigniter

我遇到了CodeIgniter Session的问题。我的应用程序是基于Ajax的,并且依赖于存储在数据库中的用户会话来正确访问和导航我的webapp。我不知道为什么,但我的会话正在被破坏,甚至将* sess_expiration *定义为 0 。我设置这样的会话配置:

$config['sess_cookie_name']         = 'cookie';
$config['sess_expiration']          = 0;
$config['sess_expire_on_close']     = TRUE;
$config['sess_encrypt_cookie']      = TRUE;
$config['sess_use_database']        = TRUE;
$config['sess_table_name']          = 'control';
$config['sess_match_ip']            = FALSE;
$config['sess_match_useragent']     = TRUE;
$config['sess_time_to_update']      = 120;

我可以做些什么来保持我的会话活着?

2 个答案:

答案 0 :(得分:1)

将您的配置更改为

 $config['sess_cookie_name'] = 'ci_session';
 $config['sess_expiration'] = 7200;
 $config['sess_expire_on_close'] = FALSE;
 $config['sess_encrypt_cookie'] = FALSE;
 $config['sess_use_database'] = FALSE;
 $config['sess_table_name'] = 'control';
 $config['sess_match_ip'] = FALSE;
 $config['sess_match_useragent'] = TRUE;
 $config['sess_time_to_update'] = 300;
 $config['sess_persistant_cookie'] = FALSE;

答案 1 :(得分:1)

这是一个非常常见的Codeigniter问题。我遇到了很多问题,但最后它适用于这个配置:

$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 604800; // 604800 = 1 week
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 604800; // 604800 = 1 week