Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 发送缓存控制标头在Codeigniter中不起作用_Php_Http_Codeigniter - Fatal编程技术网

Php 发送缓存控制标头在Codeigniter中不起作用

Php 发送缓存控制标头在Codeigniter中不起作用,php,http,codeigniter,Php,Http,Codeigniter,我可能遗漏了一些明显的东西,但我的Codeigniter应用程序在我请求时没有发送标题。 因此,在任何控制器或扩展MY_控制器中: $this->output->set_header("Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT"); $this->output->set_header("Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT"); $t

我可能遗漏了一些明显的东西,但我的Codeigniter应用程序在我请求时没有发送标题。 因此,在任何控制器或扩展MY_控制器中:

$this->output->set_header("Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT");
$this->output->set_header("Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " 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");
$this->output->set_header("Steve: it aint working you know");
我得到的标题是:

HTTP/1.1 200 OK
Date: Mon, 19 Mar 2012 18:03:06 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.6
Last-Modified: Mon, 19 Mar 2012 18:03:06 GMT
Expires: Sat, 01 Jan 2000 00:00:01 GMT
Cache-Control: post-check=0, pre-check=0, max-age=0
Pragma: no-cache
Steve: it aint working you know
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 10780
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
所以我知道它正在发送来自Steve:header的头,但它没有发送我的缓存控制设置。如果我注释掉缓存控制设置,它仍然显示相同的值


在哪里可以推翻这一点?是Codeigniter、PHP还是Apache?

我会检查您的Apache配置,特别是如何配置和

请注意,“在内容处理程序和输出过滤器运行之后,头被修改,允许修改传出头。”因此,可以将Apache设置为修改您在PHP中设置的头

我不是Apache专家,但这正是我解决类似问题所必须解决的问题。

我采取的步骤: 将以下内容添加到我的.htaccess文件中

<IfModule mod_headers.c>
Header add Cache-Control:  "no-store, no-cache, must-revalidate"
</IfModule>
    sudo a2enmod headers
    sudo service apache2 restart