使用浏览器后退按钮注销后查看仪表板
View the Dashboard after logout with browser back button
我是 codeigniter 框架的新手。我知道这个问题已经被问过很多次了。我已经完成了研发,但我无法让它工作。我现在被困住了。我正在使用 codeigniter 框架 2.2.2。我使用会话登录如下:
登录控制器
public function loginMe()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required|max_length[32]|');
if($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$result = $this->login_model->loginMe($username, $password);
if(count($result) > 0)
{
foreach ($result as $res)
{
$sessionArray = array('userId'=>$res->userId,
'role'=>$res->roleId,
'roleText'=>$res->role,
'name'=>$res->name,
'isLoggedIn' => TRUE
);
$this->session->set_userdata($sessionArray);
redirect('/dashboard');
}
}
else
{
$this->session->set_flashdata('error', 'Username or password mismatch');
redirect('/login');
}
}
}
当用户注销时,我在用户控制器中调用注销函数:
用户控制器注销功能:
function logout() {
$this->session->sess_destroy ();
ob_clean();
redirect ('login');
}
到目前为止一切正常。我可以注销登录页面,但是当我单击浏览器后退按钮时,我可以看到仪表板。这是不应该做的。
我的用户控制器构造函数正在检查会话或 isloggedin()。
public function __construct()
{
parent::__construct();
ob_start();
$this->load->model('user_model');
$this->isLoggedIn();
}
function isLoggedIn() {
$isLoggedIn = $this->session->userdata ( 'isLoggedIn' );
if (! isset ( $isLoggedIn ) || $isLoggedIn != TRUE || empty($isLoggedIn)) {
$this->session->set_flashdata('error', 'Session has Expired');
redirect ( 'login' );
} else {
$this->role = $this->session->userdata ( 'role' );
$this->vendorId = $this->session->userdata ( 'userId' );
$this->name = $this->session->userdata ( 'name' );
$this->roleText = $this->session->userdata ( 'roleText' );
$this->lastLogin = $this->session->userdata ( 'lastLogin' );
$this->global ['name'] = $this->name;
$this->global ['role'] = $this->role;
$this->global ['role_text'] = $this->roleText;
$this->global ['last_login'] = $this->lastLogin;
}
}
我已尽我所能,但它不起作用。我已经关注了这个。但它不能解决我的问题。在这方面的任何帮助将不胜感激。提前致谢。
你必须把cache-controlheaders,像这样:
$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");
您可以授权一个函数来清除缓存并在构造函数中调用它。
function clear_cache()
{
$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 框架的新手。我知道这个问题已经被问过很多次了。我已经完成了研发,但我无法让它工作。我现在被困住了。我正在使用 codeigniter 框架 2.2.2。我使用会话登录如下:
登录控制器
public function loginMe()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required|max_length[32]|');
if($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$result = $this->login_model->loginMe($username, $password);
if(count($result) > 0)
{
foreach ($result as $res)
{
$sessionArray = array('userId'=>$res->userId,
'role'=>$res->roleId,
'roleText'=>$res->role,
'name'=>$res->name,
'isLoggedIn' => TRUE
);
$this->session->set_userdata($sessionArray);
redirect('/dashboard');
}
}
else
{
$this->session->set_flashdata('error', 'Username or password mismatch');
redirect('/login');
}
}
}
当用户注销时,我在用户控制器中调用注销函数:
用户控制器注销功能:
function logout() {
$this->session->sess_destroy ();
ob_clean();
redirect ('login');
}
到目前为止一切正常。我可以注销登录页面,但是当我单击浏览器后退按钮时,我可以看到仪表板。这是不应该做的。 我的用户控制器构造函数正在检查会话或 isloggedin()。
public function __construct()
{
parent::__construct();
ob_start();
$this->load->model('user_model');
$this->isLoggedIn();
}
function isLoggedIn() {
$isLoggedIn = $this->session->userdata ( 'isLoggedIn' );
if (! isset ( $isLoggedIn ) || $isLoggedIn != TRUE || empty($isLoggedIn)) {
$this->session->set_flashdata('error', 'Session has Expired');
redirect ( 'login' );
} else {
$this->role = $this->session->userdata ( 'role' );
$this->vendorId = $this->session->userdata ( 'userId' );
$this->name = $this->session->userdata ( 'name' );
$this->roleText = $this->session->userdata ( 'roleText' );
$this->lastLogin = $this->session->userdata ( 'lastLogin' );
$this->global ['name'] = $this->name;
$this->global ['role'] = $this->role;
$this->global ['role_text'] = $this->roleText;
$this->global ['last_login'] = $this->lastLogin;
}
}
我已尽我所能,但它不起作用。我已经关注了这个
你必须把cache-controlheaders,像这样:
$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");
您可以授权一个函数来清除缓存并在构造函数中调用它。
function clear_cache()
{
$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");
}