Proposed improving of core Output library (set_header) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Proposed improving of core Output library (set_header) (/showthread.php?tid=5074) |
Proposed improving of core Output library (set_header) - El Forum - 01-04-2008 [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"); 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) Line 186 Code: // Are there any server headers to send? 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 |