【问题标题】:Not properly redirected in template library - Codeigniter在模板库中未正确重定向 - Codeigniter
【发布时间】:2012-01-16 08:19:07
【问题描述】:

我在重定向时遇到问题。我正在使用威廉姆斯模板库。除了重定向之外,一切都可以找到。用户点击退出按钮后仍可访问主页。这是我的代码:

页面控制器:

class Page extends CI_Controller {    
function index()
{
    $this->load->helper('form');
    $this->template->write_view('header','header');
    $this->template->write_view('content','login');
    $this->template->write_view('sidebar','sidebar');
    $this->template->render();
    }
}

家庭控制器:

class Home extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->library('session');
        $this->load->model('user_model','check',TRUE);
        if(!$this->check->checkUserLogin())
        {
            redirect('page');
        } 

    }

    function index()
    {
        $this->template->write_view('header','header');
        $this->template->write_view('content','home');
        $this->template->write_view('sidebar','sidebar');
        $this->template->render();
    }
}

我已经终止了会话,但是当用户单击“返回”按钮时,仍然可以查看主页。但是如果用户刷新页面,那么代码会按预期工作。

请帮忙

【问题讨论】:

标签: php model-view-controller codeigniter


【解决方案1】:

您可以尝试在 html 的 head 部分中使用以下两行代码之一:

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

基本上这些都做同样的事情。这样做的一个缺点是,除非您的网站内容随着每次页面加载而变化,否则用户必须每次都重新加载页面,而不是利用浏览器缓存机制提供的速度。您必须决定防止您描述的后退按钮问题的重要性。请记住,如果用户关闭浏览器或浏览器在按下后退按钮之前停留的时间足够长,您可能会发现此问题不存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-07
    • 2015-08-21
    • 2020-09-08
    • 2018-07-07
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多