我正在使用Codeigniter,我的问题是相同的。当用户注销后单击后退按钮时,我如何重定向到主页?
我在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');
}
但未找到解决方案。。。。
您能指定。。。更多,因为后退按钮只会带你进入上一页,可能是也可能不是主页。。。重定向用户的一种简单方法可以是
重定向(http://localhost/.....the期望的url);
我曾经遇到过一个问题,我想在用户登录后将其重新引导到上一页,但问题是上一页是登录表单,而不是用户用于混合以登录表单的页面
解决方案i通过将所需的页面地址添加到会话
$this->session->set_userdata('redirect',current_url());
然后在登录后通过重定向用户
$redirect=$this->session->userdata('redirect')
重定向($redirect);
这个问题很可能会用javascript解决,因为php不会在使用"返回"按钮时执行。
在每个页面加载上运行一个ajax,简单地检查您是否登录,如果没有,则相应地重定向。
或者您可以在单击注销按钮时这样做。
<script type="text/javascript">
window.open('http://example.com/do_logout');
self.close();
</script>
我不完全确定是否所有浏览器都支持它,但理论上,这将打开一个新的选项卡,关闭当前选项卡,从而消除"返回"的可能性。
您可以使用以下元标记控制缓存:
<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
这对我来说很好!!!
<?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');
}
}