hSATAC

>> ('cat' + 'ash').reverse #=> "hsatac"

CodeIgniter 1.7 Session Bug Within Object Storage

I don’t know whether it’s a bug or what.
I would store a object in session sometimes, like this.

$this->session->set_userdata('session_name', $object);
before 1.7, it worked just fine. But when I trying to upgrade my application to CI 1.7, it came wrong.

It will cause error messages like this:

A PHP Error was encountered

Severity: 4096

Message: Object of class stdClass could not be converted to string

Filename: libraries/Session.php

Line Number: 715 When I digged into 1.7 Session library, I found the problem.

Fixed a bug in the Session class that was disallowing slashes in the serialized array.
There are some new functions in Session library.

GOTO line 683 and line 714,

$data[$key] = str_replace('', '\\', $val);
When $val is a object, it came wrong, just replace this line with
if(!is_object($val)) $data[$key] = str_replace('', '\\', $val);
For those who got the same problem, this is my solution.
Hope there will be a hotfix soon.

I also made my own hotfix for this problem.

I made a session_fix library extends the original Session library,
only overrides these two functions.

Get my code from here and put it into /system/application/libraries/Session_fix.php

Load this library with a CI 1.7 new feature:

$this->load->library('session_fix', '', 'session');
Now it’s done!

Comments