如何禁用codeigniter中的后退按钮? [英] how to disable the back button in codeigniter?
本文介绍了如何禁用codeigniter中的后退按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Codeigniter PHP的新手。我已经在用户登录时开发了一个简单的用户管理系统,我已经设置了数据库会话。我也会在注销时销毁它们。我的缓存也被关闭。即使当我单击浏览器上的后退按钮时,我也可以看到我的仪表板,如果我单击任何链接,它会将我重定向到登录名,但首先显示的是仪表板,这是一个错误。请帮我解决。
I am newbie in Codeigniter PHP. I have developed a simple user management system in this on user login i have set database session. I also destroy them on logout. My Caching is also turned off. Even though when i click on back button on browser i can see my dashboard,if i click on any link then it redirects me to login,but it shows me the dashboard at first which is a bug. Please help me solve it.
型号:
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');
}
推荐答案
尝试通过使用禁用缓存:
Try to disable cache by using :
<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")); ?>">
也可以尝试在下面添加:
Also try to add below :
$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");
这篇关于如何禁用codeigniter中的后退按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文