【发布时间】:2018-03-26 22:59:25
【问题描述】:
我正在尝试在 codeigniter 中使用会话。我做了什么:
if ( verifyHashedPassword($this->input->post('teacher_password'),$result['teacher_password']))
{
$this->session->set_userdata('teacher_email',$this->input->post('teacher_email'));
$responseArray['success'] = true;
}
我正在尝试使用:
if ( $this->session->userdata('teacher_email') )
{
echo "session is set.";
}
else
{
echo "session is not set.";
}
重定向到此页面后。我总是没有设置会话。为什么会这样?
会话和cookie配置是:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
/*
|--------------------------------------------------------------------------
| Cookie Related Variables
|--------------------------------------------------------------------------
|
| 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
| 'cookie_path' = Typically will be a forward slash
| 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists.
| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
|
| Note: These settings (with the exception of 'cookie_prefix' and
| 'cookie_httponly') will also affect sessions.
|
*/
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
【问题讨论】:
-
你在两个页面进程中都加载会话类吗?
-
你的意思是会话库?我正在将它加载到我的控制器构造函数中。
-
在设置会话数据之前回显
$this->input->post('teacher_email')。也许,它是空的 -
不是我检查过,验证过。
-
你的问题和我刚才在stackoverflow.com/questions/43720370/…解释的一样,不是说没有其他问题,先解决
$config['sess_save_path']吧。
标签: php codeigniter session