Codeigniter按下注销按钮并禁用后退浏览器按钮 [英] Codeigniter pressing logout button and disable the back browser button

查看:54
本文介绍了Codeigniter按下注销按钮并禁用后退浏览器按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我使用的是CodeIgniter Framework,注销后出现问题,会话已被破坏并重定向到登录表单,重定向到登录表单后,浏览器后退按钮可以返回到仪表板,但存在错误因为会话已被破坏.我想要做的就是禁用浏览器的后退按钮或我以前无法加载的任何东西.我已经阅读了有关此问题的其他帖子,并尝试了他们的解决方案,但是它不起作用.我已经根据我在构造函数中另一篇文章中所阅读的内容粘贴了此代码.

Hello guys i am using CodeIgniter Framework, i have a problem within after logout, the session is already destroyed and redirect to login form, and after redirecting to login form, the browser back button can be backed to dashboard but there are errors because of the session was destroyed already. All i want is to disable the back button of the browser or anything that my previous cant be loaded. I have read other posts about this problem and tried their solution but it doesn't work. I have already pasted this code based on what I've read in other post in my constructor.

The code that I've seen from the post and posted in my constructor :
 header("cache-Control: no-store, no-cache, must-revalidate");
        header("cache-Control: post-check=0, pre-check=0", false);
        // HTTP/1.0
        header("Pragma: no-cache");
        // Date in the past
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
        // always modified
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 

这是我的注销信息:

 $sess_array = array(
        'username' => ''
        );
        $this->session->unset_userdata('logged_in', $sess_array);
        $this->session->sess_destroy();
        redirect('auth', 'refresh');

这是我的仪表板:

    <li>                                 
<a href="<?= base_url('auth/logout') ?>"><i3 class="glyphicon glyphicon-off"></i3> Logout</a>
   </li>

推荐答案

我很讨厌实现此选项,但是效果不佳.因此,我对此实施了新的逻辑.

I tired to implement this option but it doesn't works well. So i implement new logic on this.

只需检查是否在每个主要方法中都设置了会话.下面的代码可以帮助您

Simply check is session is set in every main methods. Below code help you

注销(在控制器中定义)

function __construct()
{
    parent::__construct();
    ob_start(); # add this
}

public function logout()
{
    $this->load->driver('cache');
    $this->session->sess_destroy();
    $this->cache->clean();
    ob_clean();
    redirect('home'); # Login form or some other page         
}

在仪表板(功能)中

public function home()
{
    $logged_in = $this->session->userdata('logged_in');
    if($logged_in != TRUE || empty($logged_in))
    {
        #user not logged in
        $this->session->set_flashdata('error', 'Session has Expired');
        redirect('user_logging'); # Login view
    }
    else
    {
        #user Logged in
        $this->load->view("viewname",$data);
    }
}

登录(功能)

$session = array(
    'username'  => $name,
    'logged_in' => TRUE
);

$this->session->set_userdata($session);

这篇关于Codeigniter按下注销按钮并禁用后退浏览器按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆