我正在使用 php codeigniter 创建一个网站。当我登录时,它会创建一个会话并重定向到主页。当我注销时,它会破坏会话。当我写主页的网址时,它工作正常。但是如果我点击浏览器上的“返回一页按钮”,它会返回主页。即使主页应该检查我是否登录。我的代码如下。我希望我能清楚地解释我的困境。如果没有,请询问。提前致谢。
public function signin()
{
$this->form_validation->set_rules('email2', 'E-mail', 'required|valid_email');
$this->form_validation->set_rules('password2', 'Password', 'required|min_length[5]');
$query = "select password from user where email = '{$this->input->post('email2')}';";
if($this->form_validation->run())
{
if($this->doj_database->check_signin($query, $this->input->post('password2')))
{
$query = "select * from user where email = '{$this->input->post('email2')}';";
$data['user'] = $this->doj_database->search_with_email($query);
$newdata = array('logged_in' => TRUE);
$this->session->set_userdata($newdata);
$url = "/DIRTY_ONLINE_JUDGE/goto_home/{$data['user']['user_id']}";
redirect($url);
}
else
{
$this->load->view('wrong_login');
}
}
else
{
$this->load->view('wrong_login');
}
}
public function goto_home($id)
{
if($this->session->userdata('logged_in'))
{
$data['user'] = $this->doj_database->search_with_id($id);
$data['user']['password'] = $this->encrypt->decode($data['user']['password']);
$this->load->view('home', $data);
}
else
{
$this->load->view('not_logged_in');
}
}
public function logout()
{
$this->session->sess_destroy();
$this->load->view('index');
}