I have an application where I’m using a URL parameter to trigger a results message after a certain action and a redirect. Example flow is like this:
1. User fills out form and clicks "Update"
2. [PHP code to update DB]
3. header('Location: [next-page.php]?message=1')
4. [PHP code on checks DB for the text of message id #1 and echo the message, (e.g. "Update successful!")]
This works well initially, but with a couple of problems. The URL parameter remains after the message is displayed, so if the page is refreshed, or if the user clicks back to that page later, the message displays again. I am looking for a way to do what I described above, but only show the message the first time. I would like to avoid creating a database entity for each result message with an attribute for whether it’s been viewed already or not as that seems like overkill. How would you handle this?
One method would be to POST the form to next-page.php, then execute this code on the page:
Edit: You can also do it with Javascript. Put this on the page where your form is:
On a page where the form is like: