PHP会话修改了缓存控制标头? [英] Cache-Control Header Modified By PHP Session?

查看:103
本文介绍了PHP会话修改了缓存控制标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Zend_Controller_Response对象将图像输出到浏览器.我打算将缓存应用于图像,但是某些原因导致Cache-Control标头被覆盖.

I'm outputting an image to the browser using a Zend_Controller_Response object. It is my intention to apply caching to the image, however something is causing the Cache-Control header to be overwritten.

我的代码如下:

$this->getResponse()
    ->setHeader('Last-Modified', $modifiedTime, true)
    ->setHeader('ETag', md5($modifiedTime), true)
    ->setHeader('Expires', $expires, true)
    ->setHeader('Pragma', '', true)
    ->setHeader('Cache-Control', 'max-age=3600')
    ->setHeader('Content-Type', $mimeType, true)
    ->setHeader('Content-Length', $size, true)
    ->setBody($data);

输出(在Firebug中查看)为:

The output (as viewed in Firebug) is:

响应标题

日期
星期三,2009年3月25日格林尼治标准时间
服务器
Apache/2.2.3(Ubuntu)mod_ssl/2.2.3 OpenSSL/0.9.8c
到期
2009年3月26日,星期四,格林尼治标准时间
缓存控制
无存储,无缓存,必须重新验证,后检查= 0,预检查= 0,最大年龄= 3600
最后修改
1234872514
Etag
d3ef646c640b689b​​0101f3e03e08a524
内容长度
1452
与X-UA兼容
IE = EmulateIE7
X-Robots-Tag
noindex
保持活动
超时= 15,最大= 100
连接
保持活动
Content-Type
image/jpeg
Date
Wed, 25 Mar 2009 10:34:40 GMT
Server
Apache/2.2.3 (Ubuntu) mod_ssl/2.2.3 OpenSSL/0.9.8c
Expires
Thu, 26 Mar 2009 10:34:41 GMT
Cache-Control
no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=3600
Last-Modified
1234872514
Etag
d3ef646c640b689b0101f3e03e08a524
Content-Length
1452
X-UA-Compatible
IE=EmulateIE7
X-Robots-Tag
noindex
Keep-Alive
timeout=15, max=100
Connection
Keep-Alive
Content-Type
image/jpeg

请求标头

主机
大厅.####.###.######.com
User-Agent
Mozilla/5.0(X11; U; Linux i686; en-US; rv:1.9.0.7)Gecko/2009030422 Ubuntu/8.04(hardy)Firefox/3.0 .7
接受
text/html,application/xhtml + xml,application/xml; q = 0.9,*/*; q = 0.8
接受语言
en-gb,en; q = 0.5
接受编码
gzip,放气
Accept-Charset
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7
保持活动
300
连接
保持活动
Referer
http://khall.####.###.######.com/
Cookie
PHPSESSID = abf5056e1289d3010448107632a1c1bd
Host
khall.####.###.######.com
User-Agent
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.7) Gecko/2009030422 Ubuntu/8.04 (hardy) Firefox/3.0 .7
Accept
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language
en-gb,en;q=0.5
Accept-Encoding
gzip,deflate
Accept-Charset
ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive
300
Connection
keep-alive
Referer
http://khall.####.###.######.com/
Cookie
PHPSESSID=abf5056e1289d3010448107632a1c1bd

如您所见,缓存控件被修改为包括:

As you can see, the cache control is modified to include:

无存储,无缓存,必须重新验证,后检查= 0,预检查= 0

no-store, no-cache, must-revalidate, post-check=0, pre-check=0

我怀疑请求中发送的会话cookie.有人知道一种发送我所需的标头的方法,但仍将会话保留在请求中吗?我的应用程序通过引导程序运行,并且使用Zend_Session处理会话.

My suspicion is towards the session cookie being sent in the request. Does anybody know a way to send the header that I require, yet still keep the session in the request? My application is run through a bootstrap, and sessions are handled using Zend_Session.

任何帮助将不胜感激.

推荐答案

在Zend_Controller文档中, 10.9.响应对象

From the Zend_Controller documentation, section 10.9. The Response Object

setHeader($ name,$ value,$ replace = false)用于设置个人 标头.默认情况下,它不 替换相同的现有标头 对象中的名称;但是,设置 $ replace为true将迫使它去做 如此.

setHeader($name, $value, $replace = false) is used to set an individual header. By default, it does not replace existing headers of the same name in the object; however, setting $replace to true will force it to do so.

您遇到的问题是,将max-age = 3600附加到了缓存控制标头中,而不是替换它.尝试将 $ replace 参数设置为 true .

The problem you are having is your max-age=3600 is being appended to the cache-control header, as opposed to replacing it. Try setting the $replace parameter to true.

这篇关于PHP会话修改了缓存控制标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆