note 46827 added to function.session-cache-limiter
| From: | pulstar at ig dot com dot br | Date: | Sun, 24 Oct 2004 21:39:02 +0000 |
| Subject: | note 46827 added to function.session-cache-limiter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-79054@lists.php.net to get a copy of this message | ||
You can find more information about to control the cache in PHP at http://www.php.net/manual/en/function.header.php
If you have a dinamic website and want to allow your visitors to use the back button after they sent
a form with the post method, the best combination I found was:
<?php
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter("must-revalidate");
// and after you start the session
session_start();
?>
I try some combinations using header("Cache-Control: no-cache, must-revalidate"), but when
clicking the back button, the last changes in the form back to their previous states. The
combination above works fine with IE 6.x. I didn't test this with other browsers.
When I try something like session_cache_limiter("nocache, must-revalidate") it
doesn't work. The page only updates when I used the browser's refresh button. In dynamic
web sites this is not good. The content must be fresh after each click.
I didn't find these combinations like "private, must-revalidate" documented in the
manual and I guess that something different from "none, nocache, private, public and
private_no_expire" are resolved to "none" or something like that. One thing I notice
is that in session_cache_limiter() it is "nocache", but in header() it is
"no-cache". This may give us some clues about how session_cache_limiter() function works.
About caching, the perfect solution I think is to give the correct expiration date and time and also
the right last-modified header for each element in the web site, when they are really updated. This
means a lot of extra controls of course, but may worth in web sites with high overload.
The "public" option means that all available cache in proxies and clientes will be used,
so this improves the speed of the web site and also reduces the used bandwidth. But without the
right expiration and last-modified headers, you can use it only in static web sites.
The "private" option means that only the cache in clients will be used. This is good for a
more sensitive data that can be stored locally in the browser cache. It have some benefits of the
public option, but the same restrictions too.
The "nocache" (or no-cache?) option means that the HTML portion will not be cached, but
the images, CSS and JS files will. This is good for dynamic websites because you still can use the
power of cache without loose the refreshness after each click. These files can be updated when you
open the web site or use the browser's refresh button.
I don't know why, but flash files are never updated when you click the refresh button. A common
solution for this is to change the file name when you update the flash file.
The "no-store" option means that all the content will not be cached anyway, including
images, CSS or JS files. I don't know if this applyes to flash files too, but is possible. This
option must be used with very sensitive data. I think the SSL uses this by default.
----
Manual Page -- http://www.php.net/manual/en/function.session-cache-limiter.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46827
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46827&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46827&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46827&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46827&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46827&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46827&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46827&report=yes
Search -- http://master.php.net/manage/user-notes.php