![]() |
I'm using PHP 8.1 and CI 4.3.7
I've built a filter to change HTTP caching (Cache-Control header) for some pages of my website. PHP Code: class CacheFilter implements FilterInterface I apply the filter (alias is 'cache') to the routes : PHP Code: $routes->get('page', 'PageController::view', ['filter' => 'cache']); I always end up with this values for Cache-Control in the response header: Code: Cache-Control: no-store, no-cache, must-revalidate, public, max-age=3600, s-maxage=86400 The expected response is: Code: Cache-Control: public, max-age=3600, s-maxage=86400 I tried several browsers with the same result. I tried to follow CI code up to codeigniter.php and everything seems right. So what's the problem ? Anyone has ever seen this ?
Session init in files? See session_cache_limiter() Turn off
(08-22-2023, 08:10 AM)ozornick Wrote: Session init in files? See session_cache_limiter() Turn off Yes you're totally right ! Thank you very much for your hint ![]() It led me to the solution I found. I'll develop it in my answer to Kenjis (08-22-2023, 01:48 PM)kenjis Wrote: It is already reported: Sorry, I didn't check for the issues before posting my message. I think I found the origin of the problem thanks to ozornick and a solution (that I implemented already, it works). When using sessions (when the session starts), PHP automatically sends Cache-Control instruction to the header (see my initial post). It implicitely execute this instruction: PHP Code: session_cache_limiter('nocache'); The problem is that the headers sent by session_cache_limiter() cannot be replaced or removed by CodeIgniter methods and functions such as: PHP Code: // removeHeader() does NOT remove the headers sent by session_cache_limiter() The solution is to stop theses headers from being issued BEFORE the session starts by using `session_cache_limiter('');`: PHP Code: // We prevent PHP from sending the cache related headers That's it. It's not really a bug of CodeIgniter, simply (for my part) the ignorance that when starting a session, PHP would send Cache related headers. Thanks for your help. (08-22-2023, 03:00 PM)parisiam Wrote: The solution is to stop theses headers from being issued BEFORE the session starts by using `session_cache_limiter('');`:Ok, and where in your code do you put the `session_cache_limiter('')` in order to avoid the error below? Code: session_cache_limiter(): Session cache limiter cannot be changed when a session is active I've tried in the initController method of my BaseController class without success. What is the official CI4 solution for this header duplication issue? Is there any way to take control of the Cache-Control header while using sessions in CI4? TIA. (03-01-2024, 06:32 AM)bgeneto Wrote: I've tried in the initController method of my BaseController class without success. I do it in the `app\Config\Events.php` file: PHP Code: Events::on('pre_system', static function () {
I write code in app/Common.php Before init CI
The bug will be fixed in v4.4.7.
https://github.com/codeigniter4/CodeIgniter4/pull/8601 |
Welcome Guest, Not a member yet? Register Sign In |