Codeigniter 2.1.3:sess_destroy()导致未定义的索引:session_id etc当'sess_use_database'== TRUE时 [英] Codeigniter 2.1.3: sess_destroy() causes Undefined index: session_id etc notice when 'sess_use_database' == TRUE
问题描述
我已经测试出使用数据库的会话的codeigniter的功能,当我注销(使用sess_destroy()),我得到以下通知:
I have been testing out the codeigniter's feature with sessions using database, and when ever I log out (use sess_destroy()) i get the following notices:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: session_id
Filename: libraries/Session.php
Line Number: 272
A PHP Error was encountered
Severity: Notice
Message: Undefined index: ip_address
Filename: libraries/Session.php
Line Number: 272
A PHP Error was encountered
Severity: Notice
Message: Undefined index: user_agent
Filename: libraries/Session.php
Line Number: 272
A PHP Error was encountered
Severity: Notice
Message: Undefined index: last_activity
Filename: libraries/Session.php
Line Number: 272
A PHP Error was encountered
Severity: Notice
Message: Undefined index: session_id
Filename: libraries/Session.php
Line Number: 288
A PHP Error was encountered
Severity: Notice
Message: Undefined index: last_activity
Filename: libraries/Session.php
Line Number: 289
我需要做什么来解决这个问题? (我知道我可以关闭错误报告等,但我更感兴趣的是为什么会发生这种情况,如何解决它)。
What do I need to do to fix that? (I know that I can turn off error reporting ect, but I am more interested to why this happens and how to fix it).
我用这个来创建表:
I used this to create the table:
CREATE TABLE IF NOT EXISTS `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(45) DEFAULT '0' NOT NULL,
user_agent varchar(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id),
KEY `last_activity_idx` (`last_activity`)
);
会话库是自动加载的。
推荐答案
这是导致您的问题,与2.1.3版本:
This is causing your problem, with the release of 2.1.3:
修复了一个错误#1314) - 会话库方法sess_destroy()没有销毁userdata数组。
Fixed a bug (#1314) - Session Library method sess_destroy() didn't destroy the userdata array.
$ this-> tank_auth-> logout )包含函数sess_destroy();
所以在你调用这个,你不能使用set_flashdata()在$ this - > _ show_message()。
$this->tank_auth->logout() contains the function sess_destroy(); So after you have called this, you cannot use set_flashdata() in $this->_show_message().
你需要做的是创建一个新会话。这是auth.php中您的注销方法应该是什么样子:
What you need to do is create a new session. This is how your logout method should look like in auth.php:
/**
* Logout user
*
* @return void
*/
function logout() {
$this->tank_auth->logout(); // Destroys session
$this->session->sess_create();
$this->_show_message($this->lang->line('auth_message_logged_out'));
}
这篇关于Codeigniter 2.1.3:sess_destroy()导致未定义的索引:session_id etc当'sess_use_database'== TRUE时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!