gish Posted November 23, 2008 Share Posted November 23, 2008 hi everyone I have setup up my web page so that after a form button is clicked 20 times the page automatically freshes itself. That works fine but that the creates and issue because I have pressed the submit button it posts the data then refreshed itself. but because it it refreshes anything that was posted it will ask if you want to post it again. What I want to know is there anyway to error catch it so that I dodge it or clear the post variable. gishaust Quote Link to comment Share on other sites More sharing options...
halles Posted November 23, 2008 Share Posted November 23, 2008 Try This one.. <?php function prevent_multi_submit($type = "post", $excl = "validator") { $string = ""; foreach ($_POST as $key => $val) { // this test is new in version 1.01 to exclude a single variable if ($key != $excl) { $string .= $val; } } if (isset($_SESSION['last'])) { if ($_SESSION['last'] === md5($string)) { return false; } else { $_SESSION['last'] = md5($string); return true; } } else { $_SESSION['last'] = md5($string); return true; } } /* example of use: if (isset($_POST)) { if ($_POST['field'] != "" && strlen < 25) { // place here the form validation and other controls if (prevent_multi_submit()) { // use the function before you call the database mysql_query("INSERT INTO tabel..."); // or send a mail like... mail($mailto, $sub, $body); } else { echo "The form is already processed"; } } else { // your error about invalid fiels } } */ ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.