• <legend id='4cvjx'><style id='4cvjx'><dir id='4cvjx'><q id='4cvjx'></q></dir></style></legend>

      <bdo id='4cvjx'></bdo><ul id='4cvjx'></ul>
    <tfoot id='4cvjx'></tfoot>
  • <i id='4cvjx'><tr id='4cvjx'><dt id='4cvjx'><q id='4cvjx'><span id='4cvjx'><b id='4cvjx'><form id='4cvjx'><ins id='4cvjx'></ins><ul id='4cvjx'></ul><sub id='4cvjx'></sub></form><legend id='4cvjx'></legend><bdo id='4cvjx'><pre id='4cvjx'><center id='4cvjx'></center></pre></bdo></b><th id='4cvjx'></th></span></q></dt></tr></i><div id='4cvjx'><tfoot id='4cvjx'></tfoot><dl id='4cvjx'><fieldset id='4cvjx'></fieldset></dl></div>

    <small id='4cvjx'></small><noframes id='4cvjx'>

        PHP 会话修改缓存控制标头?

        时间:2023-10-02

          <tbody id='fkfEJ'></tbody>

          1. <legend id='fkfEJ'><style id='fkfEJ'><dir id='fkfEJ'><q id='fkfEJ'></q></dir></style></legend>

            <i id='fkfEJ'><tr id='fkfEJ'><dt id='fkfEJ'><q id='fkfEJ'><span id='fkfEJ'><b id='fkfEJ'><form id='fkfEJ'><ins id='fkfEJ'></ins><ul id='fkfEJ'></ul><sub id='fkfEJ'></sub></form><legend id='fkfEJ'></legend><bdo id='fkfEJ'><pre id='fkfEJ'><center id='fkfEJ'></center></pre></bdo></b><th id='fkfEJ'></th></span></q></dt></tr></i><div id='fkfEJ'><tfoot id='fkfEJ'></tfoot><dl id='fkfEJ'><fieldset id='fkfEJ'></fieldset></dl></div>

              <small id='fkfEJ'></small><noframes id='fkfEJ'>

                <bdo id='fkfEJ'></bdo><ul id='fkfEJ'></ul>
                <tfoot id='fkfEJ'></tfoot>

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

                  问题描述

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

                  我的代码如下:

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

                  输出(在 Firebug 中查看)是:

                  响应头

                  <块引用>
                  日期
                  格林威治标准时间 2009 年 3 月 25 日星期三 10:34:40
                  服务器
                  Apache/2.2.3 (Ubuntu) mod_ssl/2.2.3 OpenSSL/0.9.8c
                  到期
                  2009 年 3 月 26 日星期四 10:34:41 GMT
                  缓存控制
                  no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=3600
                  上次修改
                  1234872514
                  Etag
                  d3ef646c640b689b​​0101f3e03e08a524
                  内容长度
                  1452
                  X-UA-Compatible
                  IE=EmulateIE7
                  X-Robots-Tag
                  noindex
                  Keep-Alive
                  timeout=15, max=100
                  连接
                  Keep-Alive
                  内容类型
                  图像/jpeg

                  请求标头

                  <块引用>
                  主机
                  khall.####.###.######.com
                  用户代理
                  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,deflate
                  Accept-Charset
                  ISO-8859-1,utf-8;q=0.7,*;q=0.7
                  保持活动
                  300
                  连接
                  保持连接
                  推荐人
                  http://khall.####.###.######.com/
                  Cookie
                  PHPSESSID=abf5056e1289d3010448107632a1c1bd

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

                  <块引用>

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

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

                  任何帮助将不胜感激.

                  解决方案

                  来自 Zend_Controller 文档,部分 10.9.响应对象

                  <块引用>

                  setHeader($name, $value, $replace =false) 用于设置个人标题.默认情况下,它不替换相同的现有标题对象中的名称;然而,设置$replace 为 true 将强制它执行所以.

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

                  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.

                  My code is as follows:

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

                  The output (as viewed in Firebug) is:

                  Response Headers

                  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

                  Request Headers

                  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:

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

                  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.

                  Any help would be appreciated.

                  解决方案

                  From the Zend_Controller documentation, section 10.9. The Response Object

                  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.

                  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 会话修改缓存控制标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Zend 框架和 Wordpress 集成 下一篇:如何设置分层 Zend 休息路线?

                  相关文章

                  最新文章

                    <bdo id='PMa7H'></bdo><ul id='PMa7H'></ul>
                2. <i id='PMa7H'><tr id='PMa7H'><dt id='PMa7H'><q id='PMa7H'><span id='PMa7H'><b id='PMa7H'><form id='PMa7H'><ins id='PMa7H'></ins><ul id='PMa7H'></ul><sub id='PMa7H'></sub></form><legend id='PMa7H'></legend><bdo id='PMa7H'><pre id='PMa7H'><center id='PMa7H'></center></pre></bdo></b><th id='PMa7H'></th></span></q></dt></tr></i><div id='PMa7H'><tfoot id='PMa7H'></tfoot><dl id='PMa7H'><fieldset id='PMa7H'></fieldset></dl></div>
                3. <tfoot id='PMa7H'></tfoot>
                4. <legend id='PMa7H'><style id='PMa7H'><dir id='PMa7H'><q id='PMa7H'></q></dir></style></legend>

                    <small id='PMa7H'></small><noframes id='PMa7H'>