| re: how to avoid resubmitting the form in php
The session-variable idea sounds the cleanest, to me. Create a session variable with a random or sequential "Transaction ID". Then, write the ID into the form in a HIDDEN variable.
[PHP]
session_start();
// Generate a $this_tid variable however you want to...
$_SESSION['tids'][$this_tid] = true;
// and when you are building your form, insert the tid field...
echo '<input type="hidden" name="tid" value="'.$this_tid.'" />';
[/PHP]
When the form is submitted, check whether the submitted transaction ID matches any in the session variable, and fail if it doesn't. If the session does
exist, delete the associated transaction ID variable and take action on the submission.
[PHP]
session_start();
if ( array_key_exists($_POST['tid'], $_SESSION['tids'] ) {
unset( $_SESSION['tids'][ $_POST['tid'] ] ); // expire the tid by deleting the array entry.
// Do stuff here
}
else {
echo "You cannot submit this form twice!"; // (and other such user-directed anger)
}
[/PHP]
|