PHP Codeigniter is showing the cache when i press

2020-02-14 06:07发布

After I logout from my app, when I press the back button, all of the login options for the user is still showed on the page.

After I login, when I press the back button it will show the logout version of the page.

I tried setting this in my logout controller

function logout() {
    $this->output->set_header('cache-Control: no-store, no-cache, must-revalidate');
    $this->output->set_header("cache-Control: post-check=0, pre-check=0", false);
    $this->output->set_header("Pragma: no-cache");
    $this->output->set_header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
    $this->tank_auth->logout();
    redirect(subdomain() . 'home');
}

But the cache is still there when i press the back button. How can i fix this?

-----UPDATE------

I think caching is not the problem here, I disabled caching in chrome in developer settings but my browser is still going to the secured page after logout when i press the back button.

So caching is not the problem..

3条回答
smile是对你的礼貌
2楼-- · 2020-02-14 06:19

REad this i think its very useful to you

https://www.codeigniter.com/user_guide/libraries/caching.html

https://www.codeigniter.com/user_guide/database/caching.html

and try this

$this->cache->clean();

or

$this->db->cache_delete_all();
查看更多
狗以群分
3楼-- · 2020-02-14 06:30

just add this to your controller

 public function __construct()
      {
          parent::__construct();

           $this->output->set_header('Last-Modified:'.gmdate('D, d M Y H:i:s').'GMT');
           $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
           $this->output->set_header('Cache-Control: post-check=0, pre-check=0',false);
           $this->output->set_header('Pragma: no-cache');
    }
查看更多
仙女界的扛把子
4楼-- · 2020-02-14 06:31

Hello sorry for saying that caching is not the problem. Caching is the problem! I fixed this by putting this code in the index.php file of the codeigniter.

header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
查看更多
登录 后发表回答