我是Codeigniter PHP的新手。我在用户登录时开发了一个简单的用户管理系统,我已经设置了数据库会话。我也在退出时销毁它们。我的缓存也被关闭了。即使我点击浏览器上的后退按钮我可以看到我的仪表板,如果我点击任何链接然后它重定向我登录,但它首先显示仪表板这是一个错误。请帮我解决一下。
型号:
public function login ()
{
$user = $this->get_by(array(
'email' => $this->input->post('email'),
'password' => $this->hash($this->input->post('password')),
), TRUE);
if (count($user)) {
// Log in user
$data = array(
'name' => $user->name,
'email' => $user->email,
'id' => $user->id,
'loggedin' => TRUE,
);
$this->session->set_userdata($data);
}
}
public function logout ()
{
$this->session->sess_destroy();
$this->session->unset_userdata('logged_in','id','name','email');
}
public function loggedin ()
{
return (bool) $this->session->userdata('loggedin');
}
控制器:
public function login ()
{
// Redirect a user if he's already logged in
$dashboard = 'user/dashboard';
$this->userlogin_m->loggedin() == FALSE || redirect($dashboard);
// Set form
$rules = $this->userlogin_m->rules;
$this->form_validation->set_rules($rules);
// Process form
if ($this->form_validation->run() == TRUE) {
// We can login and redirect
if ($this->userlogin_m->login() == TRUE) {
redirect($dashboard);
}
else {
$this->session->set_flashdata('error', 'That email/password combination does not exist');
redirect('user/secure/login', 'refresh');
}
}
// Load view
$this->data['subview'] = 'user/secure/login';
$this->load->view('user/_layout_modal', $this->data);
}
public function logout ()
{
$this->userlogin_m->logout();
redirect('user/secure/login');
}
答案 0 :(得分:2)
尝试使用以下命令禁用缓存:
<META HTTP-EQUIV="Pragma" CONTENT="private">
<META HTTP-EQUIV="Cache-Control" CONTENT="private, max-age=5400, pre-check=5400">
<META HTTP-EQUIV="Expires" CONTENT="<?php echo date(DATE_RFC822,strtotime("1 day")); ?>">
还尝试添加以下内容:
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache");