Welcome Guest, Not a member yet? Register   Sign In
Slight Session bug (or I'm dumb)
#1

[eluser]Unknown[/eluser]
Hi all - I hope that at the very least this helps someone down the road, or at best it's a bug that can be easily fixed. I do not profess to be an expert so perhaps there is something I'm doing wrong, but the fix I found solves the problem and, if integrated into CI, should not harm anything.

The situation is this: I have two large arrays that I am storing to my CI_Sessions database table (userdata). These arrays combined were so large once serialized that I had to change the userdata field from TEXT to MEDIUMTEXT. These arrays also contain a mixture of regular text, some html code, and - for good measure - characters in just about every language. Whether I should even be storing my data this way is another question. (Basically I am parsing huge xml files, allowing users to select sections of XML they want to work with and then processing sections of that XML. )

When I tested this out on a relatively small and uncomplicated input file, things worked fine. However, when I ran the process on a larger, more complex, multilanguage file, the program bombed out on me at the point where userdata was stored and retrieved. After a few hours of backtracking through the code up to the point of the core CodeIgniter files, it appeared that the userdata was being stored, but when it came time to retrieve the session data, the 'unserialize' feature was bombing out with an 'error at offset'. After researching this error it basically means that something was making it past the serialization yet still included an invalid character that breaks the unserialization process.

A suggestion found on multiple sites was to convert your serialized string to base64 prior to saving to the database, and then decoding base64 prior to unserializing.

The two changes I made in Session.php library are:

In function "_serialize":
change "return serialize($data);" to "return base64_encode(serialize($data));"

and in function "_unserialize":
change "$data = @unserialize(strip_slashes($data))" to "$data = @unserialize(strip_slashes(base64_decode($data)));"
#2

[eluser]simshaun[/eluser]
What encoding is your database/table/fields set to?
Ensure its UTF-8 if storing multiple charsets.

If not, then that could be causing your error.




Theme © iAndrew 2016 - Forum software by © MyBB