2012-03-19 76 views
1

我可能錯過了一些明顯的東西,但是我的Codeigniter應用程序在我提出要求時未發送標題。 所以在任何控制器或擴展MY_Controller:發送緩存控制標題在Codeigniter中不起作用

$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 

所以我知道它發送從史蒂夫頭:頭,但它不是送我的Cache-Control設置。如果我註釋掉Cache-Control設置,它仍然顯示相同的值。

在哪裏可以被覆蓋?它是Codeigniter,PHP還是Apache?

回答

1

我會檢查你的Apache配置,特別是如何配置mod_expiresHeader Directive

請注意,在運行內容處理程序和輸出過濾器之後,「頭部被修改,允許修改傳出頭文件。」所以Apache可能會設置爲修改您在PHP中設置的標頭。

我不是Apache專家,但這是我不得不合作解決類似問題。

+0

確定的歡呼聲,我會檢查出來多一點徹底。 – Stevo 2012-03-20 16:39:05

1

我採取的步驟: 將以下內容添加到我的.htaccess文件中。

<IfModule mod_headers.c> 
Header add Cache-Control: "no-store, no-cache, must-revalidate" 
</IfModule> 

sudo a2enmod headers 
    sudo service apache2 restart