php 在 codeigniter 中注销
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18423360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Logout in codeigniter
提问by Hacker Rocker
I am trying to design a login/logout page in codeigniter framework.My problem is that when I logout of the web-page I am getting redirected to a login page. When I go back I am getting a page which says:
我正在尝试在 codeigniter 框架中设计一个登录/注销页面。我的问题是,当我注销网页时,我被重定向到登录页面。当我回去时,我得到一个页面,上面写着:
Document Expired
This document is no longer available.
文件已过期
This document is no longer available.
But when I refresh this page I am getting logged into the system again (o.O)
但是当我刷新此页面时,我再次登录系统(oO)
The following codes contain my constructor and logout functionalities. Please help me to design a perfect login logout page
以下代码包含我的构造函数和注销功能。请帮我设计一个完美的登录登出页面
function __construct()
{
parent::__construct();
$this->load->model('user_model');
$this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
}
function logout()
{
$newdata = array(
'user_name' =>'',
'user_email' => '',
'logged_in' => FALSE,
);
$this->session->unset_userdata($newdata);
$this->session->sess_destroy();
redirect('default_controller','refresh');
}
I tried find proper logout method but I am not able to.
我尝试找到正确的注销方法,但我无法找到。
回答by Nikunj Dhimar
try to be simply like this
试着像这样
function logout()
{
$user_data = $this->session->all_userdata();
foreach ($user_data as $key => $value) {
if ($key != 'session_id' && $key != 'ip_address' && $key != 'user_agent' && $key != 'last_activity') {
$this->session->unset_userdata($key);
}
}
$this->session->sess_destroy();
redirect('default_controller');
}
回答by shams sadek
don't need to use this line
不需要使用这条线
$this->session->sess_destroy();
$this->session->sess_destroy();
回答by Aman
public function Logout()
{
$this->session->sess_destroy();
redirect('login');
}
/** Here ('login') is controller class .
In view ('logout-page'):-**/
<a href="home/logout">Logout</a>