1

I have a HTML form with information. If the submitted data is incorrect an error message will appear with a back button. A session with the submitted data is stored and filled in the form field when the user press the back button.

But I want the session to unset if the user update the site (like press F5). How can I do this?

I use this to show the stored data in the field when the user press the back button:

<b>Comment</b><br>
<textarea cols="50" rows="6" name="text">' . $_SESSION['text'] . '</textarea>

I can use unset($_SESSION['text']); at the top of the page but then the data will not show in the form. Any idea?

4

2 回答 2

1

Add unset($_SESSION['text']); at the bottom of the page.

First data will display then session will unset when user press F5.

// at the bottom of the page add below code

if(isset($_SESSION['text'])) {
    unset($_SESSION['text']);
}
于 2013-09-26T09:44:32.507 回答
1

Unset session after echoing it.

<textarea cols="50" rows="6" name="text">' . $_SESSION['text'] . '</textarea>
<?php unset($_SESSION['text']); ?>
于 2013-09-26T09:48:24.317 回答