note 64538 added to function.header

From: Date: Tue, 18 Apr 2006 06:53:45 +0000
Subject: note 64538 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-108371@lists.php.net to get a copy of this message
When using HTML forms, using the browser's back button will sometimes display a message regarding using cached data, and will ask you to refresh the page. This can be very disconcerting for some users, as they might not know whether to hit Refresh or not. To force pages to always load the data that was entered in the form prior to hitting a submit button, and prevent the browser's cache message from displaying, use the following code: <?php // Original code found at http://www.mnot.net/cache_docs/ header("Cache-Control: must-revalidate"); $offset = 60 * 60 * 24 * 1; $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; header($ExpStr); ?> This will tell the browser that the page will expire in one day, and the cached form data will be used without prompting the user at all. I have tested this in Internet Explorer 6, Firefox 1.5, and Opera 8.51, and it works as intended. I have tried other cache-control and expiry variants, but they either do not work, or do not work in every browser. This code appears to be a winner. ---- Server IP: 203.114.129.125 Probable Submitter: 222.152.189.79 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.header.php Edit -- http://master.php.net/note/edit/64538 Del: integrated -- http://master.php.net/note/delete/64538/integrated Del: useless -- http://master.php.net/note/delete/64538/useless Del: bad code -- http://master.php.net/note/delete/64538/bad+code Del: spam -- http://master.php.net/note/delete/64538/spam Del: non-english -- http://master.php.net/note/delete/64538/non-english Del: in docs -- http://master.php.net/note/delete/64538/in+docs Del: other reasons-- http://master.php.net/note/delete/64538 Reject -- http://master.php.net/note/reject/64538 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#108371) next »