note 25777 added to function.session-cache-limiter
| From: | php at rack1 dot php dot net | Date: | Sat, 05 Oct 2002 16:25:50 +0000 |
| Subject: | note 25777 added to function.session-cache-limiter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37702@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_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
http://master.php.net/manage/user-notes.php?action=edit+25777
http://master.php.net/manage/user-notes.php?action=delete+25777
http://master.php.net/manage/user-notes.php?action=reject+25777