?
Solved

unset POST

Posted on 2006-04-28
8
Medium Priority
?
992 Views
Last Modified: 2013-12-13
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
0
Comment
Question by:fradolcino
8 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 16560365
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
 

Author Comment

by:fradolcino
ID: 16560786
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
 
LVL 49

Expert Comment

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

-r-
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 40

Accepted Solution

by:
Richard Quadling earned 200 total points
ID: 16561263
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
 
LVL 9

Expert Comment

by:tolgaong
ID: 16561828
function cleanPostVars(){
    if (isset($HTTP_POST_VARS)) $HTTP_POST_VARS = array();
    if (isset($_POST)) $_POST = array();
    }

cleanPostVars();
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16561834
But that is of no use as the $_POST data will still be sent when the user presses F5 to refresh the page!
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 16561850
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question