Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>**Some background: Credit goes to bruce (sqlwork.com) for his excellent explanation.</p> <p><em>This web page requires data that you entered earlier in order to be properly displayed. You can send this data again, but by doing so you will repeat any action this page previously performed. Press Reload to resend that data and display this page.</em> </p> <p>Because of the sloppy coding practices of web developers browsers were forced to add this message. the scenario is as follows:</p> <p>1) user fills in form and submits (posts form) 2) the server process the post data and responds with a new page (confirm) marked as not cacheable 3) the user navigates to a new page. 4) the user press back:</p> <p>for the the browser to display the page in step 2, because its marked no-cache, it must request it from the server, in other words do the repost of the data (do step 1). here is were the sloppy coding came in, if this was an credit card charge, and repost detection was not on the server, the card is charged twice. this was (is) so common a problem, that the browsers had to detect this and warn the users.</p> <p>the best fix is in step two, the server sends a redirect to the confirm page. then when the user accesses the confirm via history or back, its a get request, not a post request and will not show the warning.</p> <p>note: webform's postback model lends itself to this problem. also avoid server transfers.</p> <p><strong>My solution</strong></p> <p>$_SESSION['home'] used to store any errors on home page. </p> <p>$_SESSION['tempEmail'] used to echo value on php form.</p> <p>Note: Use one unique session variable for each page that has a HTML form for error handling and also any session variable for each value that is echoed on HTML form. </p> <pre><code>&lt;?php session_start(); //Initialize variables not initialized without overwriting previously set variables. if(!isset($_SESSION['home'])) { $_SESSION['home']=""; $_SESSION['tempEmail']=""; } </code></pre> <p>Optional - If logged in, assign email address to the $_SESSION['tempEmail'] variable (if not previously done) to pre-fill HTML form. </p> <pre><code>if(isset($_POST['Submit'])){ ---your code--- //Error message(s) examples $_SESSION['home'] = "Email and Password do not match, please try again."; header("Location: " . $_SERVER['REQUEST_URI']); $_SESSION['home'] = "Email address format is invalid. Please recheck."; header("Location: " . $_SERVER['REQUEST_URI']); //success unset ($_SESSION['home']); //optional, unset to clear form values. header ("location: nextpage.php"); ---or--- header("Location: " . $_SERVER['REQUEST_URI']); //re-post to same page with the $_SESSION['home'] success message. } ?&gt; &lt;body&gt; </code></pre> <p>Error box</p> <pre><code>&lt;span&gt;&lt;strong class="error"&gt;&lt;?php echo $_SESSION['home'] ?&gt;&lt;/strong&gt;&lt;/span&gt; </code></pre> <p>HTML form</p> <pre><code>&lt;form action="#" name="loginform" method="post" &gt; &lt;input type="text" name="userEmail" maxlength="50" title="Enter Your email" autocomplete="off" value="&lt;?php echo htmlspecialchars($_SESSION['tempEmail']); ?&gt;" placeholder="enter email" required/&gt; &lt;input type="submit" name="Submit" value="Submit"&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p>Not recommended to use on payment page,see discussion above. Tested in Firefox, Chrome, Safari, and IE9. The annoying messages are gone when using back button. Ensure that output buffering is turned "on" in your php script or php.ini to avoid header warnings. You can check your php.ini file for the following;</p> <pre><code>output_buffering=On </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload