CodeIgniter Forums
CI session library BUG? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: CI session library BUG? (/showthread.php?tid=19663)

Pages: 1 2


CI session library BUG? - El Forum - 06-15-2009

[eluser]vps4[/eluser]
/* Location: ./system/libraries/Session.php */
line: 270-282

Code:
if (count($custom_userdata) === 0)
        {
            $custom_userdata = '';
        }
        else
        {
            // Serialize the custom data array so we can store it
            $custom_userdata = $this->_serialize($custom_userdata);
        }

        // Run the update query
        $this->CI->db->where('session_id', $this->userdata['session_id']);
        $this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata));

AND http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

Code:
CREATE TABLE IF NOT EXISTS  `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(16) DEFAULT '0' NOT NULL,
user_agent varchar(50) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id)
);

the bug is:

Code:
user_data text NOT NULL
when
Code:
$custom_userdata = '';


this line will get error:
Code:
$this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata));

How can I fix it?
change database table to :
Code:
user_data text NULL

OR modify
/* Location: ./system/libraries/Session.php */
like:
Code:
if (count($custom_userdata) === 0)
        {
            $custom_userdata = '';
                        return false;
        }



CI session library BUG? - El Forum - 06-15-2009

[eluser]Dam1an[/eluser]
I think this was a delibrate assumption, that you would only need the database to store session data if you
a) have lots of session data
b) Need some sort of security, track if a user is logged in, user_id etc

With your second suggested solution, would that not cause problems trying to fetch the data, as it doesn't exist, so it would deserialize a null query?


CI session library BUG? - El Forum - 06-15-2009

[eluser]TheFuzzy0ne[/eluser]
That field should never be NULL anyway, as it should contain data pertaining to the session, such as ID, last activity, user agent and so on. An empty string is NOT NULL, so I don't see the problem.


CI session library BUG? - El Forum - 06-15-2009

[eluser]Dam1an[/eluser]
Actually, the CI session data (ID, last activity, user agent and IP address) all have dedicated field, but you make a valid point with the empty string not being null


CI session library BUG? - El Forum - 06-15-2009

[eluser]TheFuzzy0ne[/eluser]
You're right. Sorry, that was a bit of an oversight on my part.


CI session library BUG? - El Forum - 06-15-2009

[eluser]vps4[/eluser]
[quote author="Dam1an" date="1245083324"]I think this was a delibrate assumption, that you would only need the database to store session data if you
a) have lots of session data
b) Need some sort of security, track if a user is logged in, user_id etc

With your second suggested solution, would that not cause problems trying to fetch the data, as it doesn't exist, so it would deserialize a null query?[/quote]

I just ask for solution, i have not fix it...


CI session library BUG? - El Forum - 06-15-2009

[eluser]TheFuzzy0ne[/eluser]
What error are you getting? To my knowledge this is not a bug.


CI session library BUG? - El Forum - 06-15-2009

[eluser]vps4[/eluser]
[quote author="TheFuzzy0ne" date="1245110298"]What error are you getting? To my knowledge this is not a bug.[/quote]

I run redux_auth

the error:
Code:
A Database Error Occurred

Error Number: 1364

Field 'user_data' doesn't have a default value

INSERT INTO `sessions` (`session_id`, `ip_address`, `user_agent`, `last_activity`) VALUES ('4a6595cfbc2d87aea1453701eb3e219c', '127.0.0.1', 'Opera/9.63 (Windows NT 5.1; U; Edition IBIS; zh-cn', 1245093099)



CI session library BUG? - El Forum - 06-15-2009

[eluser]Dam1an[/eluser]
Are you using redux auth 1.4 or 2? As they both have differant schemas for the sessions table
1.4 doesn't have a field for userdata which is wierd :S


CI session library BUG? - El Forum - 06-15-2009

[eluser]TheFuzzy0ne[/eluser]
So the problem is with Redux and not CodeIgniter?