Php Codeigniter:在跨控制器重定向期间避免浏览器缓存

Php Codeigniter:在跨控制器重定向期间避免浏览器缓存,php,caching,header,codeigniter-2,Php,Caching,Header,Codeigniter 2,我试图在我的Codeigniter项目中避免浏览器缓存。我发现这个答案很有帮助。我在控制器中通过以下代码设置输出标题: $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->s

我试图在我的Codeigniter项目中避免浏览器缓存。我发现这个答案很有帮助。我在控制器中通过以下代码设置输出标题:

    $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");

它在大多数情况下都能正常工作。但当我重定向到某个其他控制器类的控制器方法时,这个过程不起作用。在重定向到其他控制器时,我应该如何设置无缓存头?

我发现了问题。重定向到其他控制器时,将输出标题设置为$this reference是不正确的。因为通过使用$this引用设置header只会影响该控制器的输出类

要避免缓存跨控制器缓存,必须如下设置标头:

header("Cache-Control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");
您还可以从重定向的目标类设置头。但是为了避免缓存表单提交,上面的过程很好