|
|
|
Do you have enough from submitting the same form multiple times to your database and/or mail? Then this should be your solution. With this function (and also session support) is it possible prevent the user to post a form twice (or more) while using server side form field validation. The script checks the unique string from the current submission against the post before and stops if the string is the same.
| <?php
function prevent_multi_submit($type = "post") { // use "get" if this is your form method
session_start();
$string = "";
$posted_array = ($type == "get") ? $_GET : $_POST;
foreach ($posted_array as $val) {
$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
}
} */
?> | | |
|
| Demo of Alternate Pagination Paradigm (Paging) Categories : PHP, User Interface, Sessions | | | XDT Topsite (Gold v1.0) Categories : Databases, CSS, PHP, HTML and PHP, Sessions | | | Problem passing session variables Categories : Sessions, PHP | | | GuestBook Light - a plug and play application for any website. Categories : PHP, Complete Programs, Filesystem, Sessions | | | A beginner's session handling class Categories : PHP, PHP Classes, Sessions, Beginner Guides | | | Sessions Stored into the Database Categories : PHP, Sessions | | | base64 with encryption - encode and decode sessions Categories : PHP, PHP Classes, Encryption, Sessions | | | A simple PHP login script that you can modify to suite your needs. It use a session to store data in a session file submited by the page. Categories : PHP, Sessions, Security, Authentication | | | SPL and ITERATOR : examples Categories : PHP, Object Oriented, PHP Classes, Sessions | | | Form Security - Match A Value For Success Categories : PHP, Authentication, HTML and PHP, Sessions, Security | | | AITSH Statistics Categories : Complete Programs, Databases, HTML and PHP, Sessions, PHP | | | Session Validation Methods (Security Checks) Categories : PHP, Sessions, Security | | | How to implement a session tracking system. Categories : PHP, Sessions, Variables | | | CAPTCHA[Image verification] Categories : PHP, Security, GD image library, Graphics, Sessions | | | Simple Session example Categories : PHP, Beginner Guides, Sessions | |
| | | | paul taylor wrote :1269
Nice function Olaf.
Will be very useful
| |
|
|
|