在我的CI项目会话中,userdata返回空字符串。我曾尝试在config.php中配置会话变量,但我无法解决此问题。任何人都可以帮我修理吗?
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['cookie_prefix'] = "";
$config['cookie_domain'] = $_SERVER['HTTP_HOST'];
//$config['cookie_domain'] = "";
// $config['cookie_path'] = "/";
$config['cookie_path'] = str_replace('//','/',dirname($_SERVER['SCRIPT_NAME']).'/');
$config['cookie_secure'] = FALSE;
答案 0 :(得分:0)
您应该先定义它。
打开application / config / autoload.php并加载session
库:
$autoload['libraries'] = array('session');
按照您喜欢的方式编辑此代码:
$session = array(
'somekey' => 'somevalue',
'otherkey' => 'othervalue'
);
$this->session->set_userdata($session);
如果您想达到该值,请使用:
echo $this->session->userdata('somekey');