note 25777 modified in function.session-cache-limiter by didou

From: Date: Sun, 18 May 2003 03:23:05 +0000
Subject: note 25777 modified in function.session-cache-limiter by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-48368@lists.php.net to get a copy of this message
If you use sessions, the Cache-Control header will automatically be set to no-cache. If you want to make your response cache-able (which is useful for example for images), using session_cache_limiter('private') or session_cache_limiter('public') will set Cache-Control correctly, but the Expires date will be some nonsense date in the past (approx. 23 years ago). This is at least true for PHP 4.1.1 and 4.2.1. You won't be able to replace the incorrect Expires header though - instead the corrected date will be added after the incorrect one! The only way I have found to circumvent this misbehaviour is to set session_cache_limiter('none') and create the correct Cache-Control and Expires headers on your own. Example: session_cache_limiter('none'); $expires = ( function_exists('session_cache_expire') ? session_cache_expire() : 60 ) * 60; $gm_expires = gmdate('D, d M Y H:i:s', time() + $expires); header("Cache-control: private, max-age=$expires, pre-check=$expires"); // HTTP 1.1 header("Expires: $gm_expires GMT"); // HTTP 1.0 Note that, in order to improve responsiveness, you should also set the Last-Modified header correctly which otherwise defaults to the unix zero date (in 1970). This allows Apache to response to a request using If-Modified-Since with a 304 Not Modified, so no data will need to be re-transferred. HTH! --was-- If you use sessions, the Cache-Control header will automatically be set to no-cache. If you want to make your response cache-able (which is useful for example for images), using session_cache_control('private') or session_cache_control('public') will set Cache-Control correctly, but the Expires date will be some nonsense date in the past (approx. 23 years ago). This is at least true for PHP 4.1.1 and 4.2.1. You won't be able to replace the incorrect Expires header though - instead the corrected date will be added after the incorrect one! The only way I have found to circumvent this misbehaviour is to set session_cache_control('none') and create the correct Cache-Control and Expires headers on your own. Example: session_cache_control('none'); $expires = ( function_exists('session_cache_expire') ? session_cache_expire() : 60 ) * 60; $gm_expires = gmdate('D, d M Y H:i:s', time() + $expires); header("Cache-control: private, max-age=$expires, pre-check=$expires"); // HTTP 1.1 header("Expires: $gm_expires GMT"); // HTTP 1.0 Note that, in order to improve responsiveness, you should also set the Last-Modified header correctly which otherwise defaults to the unix zero date (in 1970). This allows Apache to response to a request using If-Modified-Since with a 304 Not Modified, so no data will need to be re-transferred. HTH! http://www.php.net/manual/en/function.session-cache-limiter.php

« previous php.notes (#48368) next »