This content has been marked as final. Show 5 replies
>How can I stop the POSTDATA message from appearing in users' browsers when they
>click back on my website.
> (The page you are trying to view contains POSTDATA that has expired from
You use a server-side script to redirect the browser to the same page.
The following GET request will "replace" the previous POST request in
the browser's history, hence no "post data expired" message will appear
anymore when going back.
In PHP you can do that with a header() call and an absolute URL:
On many of my scripts I use header(), but some scripts will set a variable based on POST data, such as '$error' if an error were to occur. If I were to use header() at the end of the script before any output is displayed, the variable would be destroyed before it could be displayed. How can I get around this issue?
The only method I could come up with is setting a $_SESSION variable (like 'error') at the end of the script just before the header function is called. Then first thing on the next page, set a variable equal to the session variable ($error = $_SESSION['error']), and then unset the session variable.
I am just not sure if this is the best and most flawless method. I fear it might be possible for something to go wrong between the two pages. Then a user loads an entirely different page and has some completely irrelevant error message appear on that page, due to a session variable still being set. The 'error' variable has the same name on all my pages.
>On many of my scripts I use header(), but some scripts will set a variable
>based on POST data, such as '$error' if an error were to occur. If I were to
>use header() at the end of the script before any output is displayed, the
>variable would be destroyed before it could be displayed. How can I get around
To carry a variable from page to page you would have to store it in a
But the question is, if you want to do the redirect at all if there was
an error. I usually only do it if the form processing was successful.
Otherwise I simply show the form again with its error messages and the
previously entered values.
Some scripts also produce a success message stored in the variable, '$msg'. Currently, if $msg is set, the success message will be displayed on the same page and the form will not be displayed. If I cannot store a success message in a variable, then the only option I see is to create a separate page for every script that normally sets a success message, simply for the purpose of displaying one.
So if someone edited their profile and the script that saves it was successful, it would set the header to something like 'edit_profile_success.php', just to tell the user that their profile was saved successfully. It just seems a bit unnecessary to create all those extra pages for every script that should display a success message.
Nobody has any ideas on this? I cannot set a message of error or success and use the header function to clear the post data because the message will be destroyed. Its like I have to choose between efficiently displaying a message, or clearing the post data so it doesn't cause problems when the visitor navigates back. I'm so confused.