CodeIgniter 1.7.3 では、set_userdata を使用してブール値、整数値、および文字列値を追加し、すぐに読み戻すと、型が保持されます。ただし、別のページにリダイレクトして値を読み返すと、常に文字列値が取得されます。CI 1.6.1 では、型は保持されます。なぜこれが起こっているのですか?1.7.3 のバグですか? 回避策はありますか?
例: test1 を実行してセッション データを設定し、それを読み戻し、test2 にリダイレクトし、再度読み戻します。
<?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));
}
}
?>
CI ログの出力
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
構成設定
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=