php - 如何告诉 Codeigniter 不要存储缓存?
问题描述
我有一个 Codeigniter 2.2 项目。在不更改代码的情况下,我的浏览器以某种方式为以前登录的用户保存了缓存。如果我通过清除缓存重新加载,那么它会显示当前登录的用户。
我添加了 My_Output 核心控制器。并$this->output->clear_cache()
在注销功能中添加。我还添加了
<IfModule mod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>
在我的 .htaccess 文件中。还是一样的问题
解决方案
您必须将正确的标头发送给客户端。
$this->output->set_header("HTTP/1.0 200 OK");
$this->output->set_header("HTTP/1.1 200 OK");
$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' 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");
$this->output->set_header("Pragma: no-cache");