unset POST

i have a input form (method=post), and after the user push the button Submit, the values is insert in a database
i want if the user push F5, or reload page do not insert into the database the post values
i try unset($_POST['value']), doesn't work
also i try unset($_HTTP_POST_VARS); and unset($_POST); same thing
doesn't work
please help
thanks
fradolcinoAsked:
Who is Participating?
 
Richard QuadlingSenior Software DeveloperCommented:
YOU have to control this.

You either deal with the fact that the data MAY be resubmitted.

Or

When the data is submitted you direct the client to a new page which redraws the order data (like Roonaan suggested).

I would recommend doing both.


When you generate the form, place in the form a hidden value containing the datetime of the page's creation. Place the same value in the session and add another flag to the session saying that the form is active ...

$dt_form_created = microtime(True);
$_SESSION['Forms'][$dt_form_created ]['Active'] => True;


When the user POSTs the form, compare the POST'ed datetime against the session. If they exist, then check the sessions 'Active' staus. If the form is active, then you can submit the data to the DB and then set the status to False. If not, then the data has already been submitted and you need to draw a new form or tell them that the data has already been submitted.
0
 
RoonaanCommented:
Hi,

You can use header('Location:someotherpage') to redirect the user to another page after they have posted. When they then press F5, they are on that new page without POST-data.

-r-
0
 
fradolcinoAuthor Commented:
no, because is a page where a client put some orders, and he MUST see that page with the evolution of the orders
thanks
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
RoonaanCommented:
Yeah, but you can easily redirect to a php page:
header('Location:view_order.php");

-r-
0
 
tolgaongCommented:
function cleanPostVars(){
    if (isset($HTTP_POST_VARS)) $HTTP_POST_VARS = array();
    if (isset($_POST)) $_POST = array();
    }

cleanPostVars();
0
 
Richard QuadlingSenior Software DeveloperCommented:
But that is of no use as the $_POST data will still be sent when the user presses F5 to refresh the page!
0
 
RoonaanCommented:
tolgaong. I actually had to grin about your solution. :^D

Although it is what was asked for, you must have noticed that it isn't going to help out with the problem described.

:^D

-r-
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.