Codeigniter set_userdata does not save types in session data

In CodeIgniter 1.7.3, when you use set_userdata to add logical, integer and string values, and then read them immediately, the types are saved. But if you redirect to another page and read the values, you always get string values. In CI 1.6.1 types will be saved. Any idea why this is happening? Is this a bug in 1.7.3? Any workarounds?

Example: run test1 to set the session data, read it back, redirect to test2 and read it again:

<?php
class Test1 extends Controller
{
    function index()
    {
        $this->session->set_userdata(array('vbool'=>TRUE));
        $this->session->set_userdata(array('vint'=>23));
        $this->session->set_userdata(array('vstr'=>'abc'));

        $vbool = $this->session->userdata('vbool');
        $vint = $this->session->userdata('vint');
        $vstr = $this->session->userdata('vstr');

        log_message('error', "test1: vbool=$vbool " . gettype($vbool));
        log_message('error', "test1: vint=$vint " . gettype($vint));
        log_message('error', "test1: vstr=$vstr " . gettype($vstr));

        redirect('/backend/test2', 'location');
    }
}
?>


<?php
class Test2 extends Controller
{

    function index()
    {
        $vbool = $this->session->userdata('vbool');
        $vint = $this->session->userdata('vint');
        $vstr = $this->session->userdata('vstr');

        log_message('error', "test2: vbool=$vbool " . gettype($vbool));
        log_message('error', "test2: vint=$vint " . gettype($vint));
        log_message('error', "test2: vstr=$vstr " . gettype($vstr));
    }

}
?>

OUTPUT in CI LOG

ERROR - 2011-05-09 16:56:11 --> test1: vbool=1 boolean
ERROR - 2011-05-09 16:56:11 --> test1: vint=23 integer
ERROR - 2011-05-09 16:56:11 --> test1: vstr=abc string

ERROR - 2011-05-09 16:56:11 --> test2: vbool=1 string
ERROR - 2011-05-09 16:56:11 --> test2: vint=23 string
ERROR - 2011-05-09 16:56:11 --> test2: vstr=abc string

CONFIGURATION SETTINGS

ERROR - 2011-05-09 16:56:11 --> sess_encrypt_cookie=
ERROR - 2011-05-09 16:56:11 --> sess_use_database=
ERROR - 2011-05-09 16:56:11 --> sess_table_name=ci_sessions
ERROR - 2011-05-09 16:56:11 --> sess_expiration=7200
ERROR - 2011-05-09 16:56:11 --> sess_match_ip=
ERROR - 2011-05-09 16:56:11 --> sess_match_useragent=1
ERROR - 2011-05-09 16:56:11 --> sess_cookie_name=ci_session
ERROR - 2011-05-09 16:56:11 --> cookie_prefix=
ERROR - 2011-05-09 16:56:11 --> cookie_path=/
ERROR - 2011-05-09 16:56:11 --> sess_time_to_update=300
ERROR - 2011-05-09 16:56:11 --> encryption_key=
+3
source share
1 answer

CodeIgniter 2.0.0, - , set_userdata(), userdata(). , , , CI 1.7.3 , , .

+1

All Articles