嗯,我已经创建了 session ,但在我的网站中实现 cookie 时遇到了问题。在配置文件中,我设置了 $config['sess_expire_on_close'] = TRUE;
以便用户的 session 在关闭浏览器时过期。
现在我想要的是,如果用户检查登录时记住我...所有数据都应存储在 cookie 中,以便在关闭浏览器时,用户仍处于登录状态。
function login($email, $password, $loginas) {
if ($loginas == 'user') {
$this->db->select('*');
$this->db->where('email', $email);
$this->db->where('password', $password);
$query = $this->db->get("user_info");
if ($query->num_rows() > 0) {
foreach ($query->result() as $rows) {
$newdata = array('id' => $rows->id,
'firstname' => $rows->firstname,
'lastname' => $rows->lastname,
'address' => $rows->address,
'city' => $rows->city,
'email' => $rows->email,
'phone' => $rows->phone,
'logged_in' => TRUE,
);
}
$this->session->set_userdata($newdata);
if ($rememberme == 'on') {
// create a cookie here with all data that i have put in session
}
return TRUE;
}
return FALSE;
}
}
创建cookie会自动创建session吗?或者我们再次手动将这些数据放入 session 中?
最佳答案
在 CodeIgniter 中,您可以使用 set_cookie()
$cookie = array(
'name' => 'The Cookie Name',
'value' => 'The Value',
'expire' => '86500',
'domain' => '.example.com',
'path' => '/',
'prefix' => 'myprefix_',
'secure' => TRUE
);
$this->input->set_cookie($cookie);
关于php - 在 Codeigniter 中创建 Cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32494636/