[eluser]instantations[/eluser]
Hello,
First of all, I hope this wasn't posted before or fixed in a newer release of CI (but I think I've been using the latest release).
I had to make this change because my pages would always be cached, despite setting the usual no-cache HTTP headers using set_header().
The proposed change aims at making the
set_header() fonction in CI more compatible with the native PHP
header() fonction.
You might know the header() function accepts these parameters :
Code:
header ( string $string [, bool $replace [, int $http_response_code ]] )
While CI set_header() only accept the string.
So the following code, found in the user guide, is useless as such (I suspect it was copy-pasted from common no-cache PHP code using the header() fonction) :
Code:
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0", false);
The second line of code actually replaces the cache-control set by the first line, instead of adding to it, since the "false" parameter in the second line is not understood the set_header() function.
My change allows set_header() to take that second "replace" parameter into account.
So in system/libraries/Output.php you must make the following 2 changes:
Line 87
Code:
function set_header($header, $replace = true)
{
$this->headers[]['header'] = $header;
$this->headers[]['replace'] = $replace;
}
Line 186
Code:
// Are there any server headers to send?
if (count($this->headers) > 0)
{
foreach ($this->headers as $header)
{
@header($header['header'], $header['replace']);
}
}
The "replace" parameter defaults to true, as in the PHP header() function. This change doesn't affect any existing code using the set_header() function.
I did not implement http_response_code cause I'm a bit lazy right now...
Cheers,
Laurent