简体   繁体   English

Codeigniter:当用户注销后单击“后退”按钮时,如何重定向到首页?

[英]Codeigniter: How can I redirect to home when user click on back button after logout?

I am using Codeigniter and my question is same How can I redirect to home when user click on back button after logout? 我正在使用Codeigniter,我的问题是相同的。 当用户注销后单击“后退”按钮时,如何重定向到首页?

I tried below code in views/header.php and also in controller top but nothing progress..! 我在views/header.php以及控制器顶部尝试了以下代码,但没有任何进展..!

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

I also tried 我也试过

  /* @author: Muhammad Sajid
   * @name: do_logout
   */
    public function do_logout()
    {
        $this->session->sess_destroy();
        $this->clearCache();
        redirect("login/index/0");
    }

    //+ Jonas Raoni Soares Silva
    //@ http://jsfromhell.com
    public function clearCache(){
        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Cache-Control: no-store, no-cache, must-revalidate');
        header('Cache-Control: post-check=0, pre-check=0', false);
        header('Pragma: no-cache');
    }

but not found solution.... 但找不到解决方案。

can you plz specify... more since the back button will just take you to the previous page which may or may not be the home page... a simple way to redirect the user can be 您可以指定...吗?更多,因为后退按钮将带您进入上一页,该页面可能是主页,也可能不是主页...重定向用户的简单方法是

redirect(http://localhost/.....the desired url); 重定向(http:// localhost / ....所需的URL);

I once had a problem that i wanted to re-direct the user to the previous page after he loged in however the problem was that the previous page was a log in form and not the page the user used for comming to log in form 我曾经有一个问题,我想在用户登录后将用户重定向到上一页,但是问题是上一页是登录表单,而不是用户用来登录表单的页面

Solution i added the desired page address to session by 解决方案我向会话添加了所需的页面地址

$this->session->set_userdata('redirect', current_url()); $ this-> session-> set_userdata('redirect',current_url());

and then after log in redirected the user by 然后登录后通过以下方式重定向用户

$redirect = $this->session->userdata('redirect'); $ redirect = $ this-> session-> userdata('redirect');
redirect($redirect); redirect($ redirect);

This issue would most likely be solved with javascript since php isn't executed upon using the Back-button. 由于使用后退按钮时不会执行php,因此最有可能使用javascript解决此问题。

Either run an ajax on each page load that simply checks if you're logged in, and redirect accordingly if not. 可以在每次页面加载时运行一个ajax,以简单地检查您是否已登录,如果没有,则相应地重定向。

Or you could maybe do like this when clicking the logout-button. 或者,您也可以在单击注销按钮时这样做。

<script type="text/javascript">
    window.open('http://example.com/do_logout');
    self.close();
</script>

I'm not fully sure if all browsers support it, but in theory that would open a new tab, close current and therefor remove the possibility to "Back". 我不确定是否所有浏览器都支持它,但是从理论上讲,这将打开一个新选项卡,关闭当前选项卡,从而消除了“返回”的可能性。

You can control cache with meta tags use following: 您可以使用以下元标记控制缓存:

<META HTTP-EQUIV="EXPIRES" CONTENT="Mon, 22 Jul 2002 11:12:01 GMT">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

for detailed information visit this link: http://www.i18nguy.com/markup/metatags.html 有关详细信息,请访问此链接: http : //www.i18nguy.com/markup/metatags.html

This is working for me nicely!!! 这很适合我!

<?php
   if ( ! defined('BASEPATH')) exit('No direct script access allowed');

   class admin extends CI_Controller
   {
      public function __construct()
      {
          parent::__construct();
          $this->no_cache();
      }

      protected function no_cache()
      {
          header('Cache-Control: no-store, no-cache, must-revalidate');
          header('Cache-Control: post-check=0, pre-check=0',false);
          header('Pragma: no-cache'); 
      }
   }

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

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