Welcome Guest, Not a member yet? Register   Sign In
Headers set to no cache are not honored?
#1

[eluser]drewbee[/eluser]
Does anyone else have this issue? Obviously, using codeigniter, I have a very dynamic site that browsers love to cache. Naturally, setting the headers (expires, validation etc etc) is how I handle this. Can anyone verify and duplicate the following problem?

This is not being honored:

Code:
$this->output->set_header("Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT"); // Date in the past
$this->output->set_header("Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT"); // always modified
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
$this->output->set_header("Cache-Control: post-check=0, pre-check=0", FALSE);
$this->output->set_header("Pragma: no-cache");


This works (Same controller, just using actual headers rather then CI's output->header function:
Code:
header("Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT"); // Date in the past
header("Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", FALSE);
header("Pragma: no-cache");
#2

[eluser]drewbee[/eluser]
Can anyone confirm this? Somehow I highly... HIGHLY doubt I am the first person to make dynamic pages with code igniter.... Smile
#3

[eluser]txomin[/eluser]
Did you find a solution to the problem? I am also most interested in this.
#4

[eluser]drewbee[/eluser]
I havn't had a chance to check out why it isn't registering correctly. I simply just used the normal header() function within my MY_Controller (Extended controller)
#5

[eluser]txomin[/eluser]
I have reached a similar conclusion. Thanks for the reply.
#6

[eluser]drewbee[/eluser]
I actually just popped open the output class and I can see any feasible reason it is not behaving with the same behavior.

Code:
/**
     * Set Header
     *
     * Lets you set a server header which will be outputted with the final display.
     *
     * Note:  If a file is cached, headers will not be sent.  We need to figure out
     * how to permit header data to be saved with the cache data...
     *
     * @access    public
     * @param    string
     * @return    void
     */    
    function set_header($header, $replace = TRUE)
    {
        $this->headers[] = array($header, $replace);
    }

Code:
function _output // Snip....
        // Are there any server headers to send?
        if (count($this->headers) > 0)
        {
            foreach ($this->headers as $header)
            {
                @header($header[0], $header[1]);
            }
        }

Weird...
#7

[eluser]slowgary[/eluser]
Did you check the actual headers that the browser is receiving? Maybe they're not getting sent, or somehow they're malformed. There are a few firefox addons that make it easy. LiveHTTPHeaders is a popular one.
#8

[eluser]dmorin[/eluser]
I'm guessing that you're somehow starting the output to the browser before the output class sends its output. For example, if you have any echo statements or even a blank line after the end php tag at the end of the file (which you shouldn't have), it will cause php to start sending output and then when the output class tries to send the headers, they won't send. Any chance this is the case?

If it is, you should be getting errors about headers already sent when CI tries. Are you getting any errors (including notices)? I would also recommend using LiveHTTPHeaders or even firebug to see what is being sent
#9

[eluser]drewbee[/eluser]
Nope. No errors are appearing. I agree I need to take a look at what headers are actually being sent.

I use a custom templating class so even the output class does not receive any of my views until my final $template->draw() is called. It is really not a big deal, I just like to stay with the CI api as much as possible.
#10

[eluser]slowgary[/eluser]
Plus if that were the case you'd see the errors when you output the headers manually as well. They must be malformed by CI or something.




Theme © iAndrew 2016 - Forum software by © MyBB