我正在使用Codeigniter,我的问题是How can I redirect to home when user click on back button after logout?
我尝试了views/header.php
以及控制器顶部中的代码,但没有任何进展......!
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
我也试过
/* @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');
}
但找不到解决方案......
答案 0 :(得分:0)
你可以plz指定...更多,因为后退按钮只会带你到上一页,可能是也可能不是主页... 一种重定向用户的简单方法可以是
重定向(http://localhost/.....the desired url);
我曾经遇到过一个问题,我想在用户进入之后将用户重新定向到上一页但问题是前一页是登录表单而不是用户用来登录的页面表格
解决方案我通过
将所需的页面地址添加到会话中$ this-> session-> set_userdata('redirect',current_url());
然后登录后通过
重定向用户$ redirect = $ this-> session-> userdata('redirect');
重定向($重定向);
答案 1 :(得分:0)
这个问题最有可能通过javascript解决,因为使用后退按钮不会执行php。
在每个页面加载上运行ajax,只检查您是否已登录,如果没有则重定向。
或者你可以在点击退出按钮时这样做。
<script type="text/javascript">
window.open('http://example.com/do_logout');
self.close();
</script>
我不完全确定所有浏览器是否支持它,但理论上会打开一个新标签,关闭当前电流并因此消除“返回”的可能性。
答案 2 :(得分:0)
您可以使用以下内容控制使用元标记的缓存:
<META HTTP-EQUIV="EXPIRES" CONTENT="Mon, 22 Jul 2002 11:12:01 GMT">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
有关详细信息,请访问此链接: http://www.i18nguy.com/markup/metatags.html
答案 3 :(得分:0)
这对我很有用!!!
<?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');
}
}