简体   繁体   English

注销后单击后退按钮重定向到网页

[英]Redirect to webpage by click on back button after logout

In the below codeigniter code after i logout i can able to view page but i want not to view page after logout . 在我注销后的下面的codeigniter代码中,我可以查看页面,但我不想在注销后查看页面。 I placed the controller below. 我把控制器放在下面。

function logout()
    {
        $this->session->sess_destroy();

        $this->index();
    }

You can try this 你可以试试这个

function logout(){

         $this->CI =& get_instance();   
         $this->CI->session->sess_destroy();
         redirect(base_url());
}

Check in each controller method which loads the page whether the person is logged in or not. 检查加载页面的每个控制器方法,无论该人是否登录。 If not redirect. 如果没有重定向。 you have to do it in each function that loads a view. 你必须在每个加载视图的函数中执行此操作。

Try this 尝试这个

function logout()
{
$this->session->sess_destroy();       
    $this->load->helper('url');
           redirect('base_url() ,'refresh');
           exit;
}

If you are attempting to restrict user from certain page with authentication you can implement some code like this : 如果您尝试使用身份验证限制某个页面的用户,您可以实现以下代码:

if($this->user->logged() == FALSE)
        { 
            redirect('login');
        }

Write down this code in your method otherwise you can write this in constructor.As for as i got from your question not from the title of your question. 在你的方法中写下这段代码,否则你可以在构造函数中写这个。因为我从你的问题得到的不是你问题的标题。

Hopefully you're using templates for your views and this will be painless but make sure this is in the head of each page you don't want accessible by the back button. 希望您使用模板进行查看,这将是无痛的,但请确保这是您不希望通过后退按钮访问的每个页面的头部。

header("Cache-Control: no-store, no-cache, must-revalidate");
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE, NO-STORE, must-revalidate">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT=0>

Just to explain what is happening. 只是为了解释发生了什么。 The page is loading from your browser cache meaning the browser thinks your user is still logged in. The above lines make the browser revalidate the page on every load and won't load it from it's own cache. 页面正在从您的浏览器缓存加载,这意味着浏览器认为您的用户仍然登录。上面的行使浏览器在每次加载时重新验证页面,并且不会从它自己的缓存加载它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM