问题描述
我可能缺少明显的东西,但我的Codeigniter应用程序未在请求时发送标头.因此,在任何控制器或扩展的MY_Controller中:
I'm probably missing something obvious, but my Codeigniter app is not sending headers when I ask it to.So in any controller or the extended MY_Controller:
$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:标头发送标头的,但是它没有发送我的Cache-Control设置.如果我注释掉Cache-Control设置,它仍然显示相同的值.
So I know it's sending headers from the Steve: header but it's not sending my Cache-Control settings. If I comment out the Cache-Control setting, it still displays the same value.
在哪里可以覆盖?是Codeigniter,PHP还是Apache?
Where could this be being overridden? Is it Codeigniter, PHP or Apache?
推荐答案
我会检查您的Apache配置,尤其是 mod_expires
和标题指令.
I would check your Apache config, particularly how mod_expires
and the Header Directive are configured.
请注意,在运行内容处理程序和输出过滤器之后立即修改标头,从而允许修改传出标头."因此,可以将Apache设置为修改您在PHP中设置的标头.
Note that the "header is modified just after the content handler and output filters are run, allowing outgoing headers to be modified." So Apache may be set to modify the headers you've set in PHP.
我不是Apache专家,但这是我必须解决的类似问题.
这篇关于发送缓存控制标头在Codeigniter中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!