Link to home
Start Free TrialLog in
Avatar of duta
duta

asked on

PHP survey form and block multiple submissions

Hi!

I just created an online suvrey form using PHP and MySQL, which is working just great. In fact, I got a lot of great from geniuses in this site.

I have a little problem: The problem is that people may submit the form as many as they want, which is certainly not what I want.

I would like to add some scripts to keep a person from submitting not more than once.

I searched an answer to a similar questions, but, for some reason, I couldn't find one.

Hope you geniuses may kindly help me again!

duta

June 11, 2006, at 1:33 pm

ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i'd prefere using both ways
saving clients' IP is a good idea but you must notice that many may share the very same id. som it would be wise to check first if a cookie variable is already present, if not, check your database to see how many times this IP did submissions, say in the last 24, you can set a limit, say only 10 times per day from the same IP!
Avatar of duta
duta

ASKER

TO: Roonaan:

Thank you so much again for your kind, prompt response.

They are what I thought  I needed to do.  The problem is that sadly I am not yet ready to put that concept into
working scripts. I already collect a respondent's IP and keep it in my MySQL database.

I will truly appreciate if you may kindly present me with an actual script. In fact, I would like to learn how to use both (cookie and IP address).

Thanks!

using IP is nod smart thing,
my ISP's IP is same for 4000 users.

i preffer you use sessions
while session is active and store value submitted
use that value to hide the form

same user will need to close browser in order to submit again
or store both IP and browser
Avatar of duta

ASKER

TO: feha:

You are fabulous. I guess you are busy responding to my question here and there.

By the way, I have never used either of them. Without actual scripts and detailed directions, I am afraid, I may not try it.  Can you kindly show me the scripts?

Thanks again!

duta

June 11, 2006, at 5:14 pm
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of duta

ASKER

TO: feha:

Thanks again!

I will try the script as soon as possible, and come back to you.

Thanks!

duta
Avatar of duta

ASKER

TO: feha:

Hi again!

I got and tested the script to prevent multiple prevention (the script is below).

I just wonder whether I need to make some changes to the script to make it work with my work. I just inserted the script into my work, but it did not work.

Thanks a lot!

duta
________________ script ______________

<?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
    }
} */
?>
Hi duta,

To have sessions running, you have to add a call to session_start() at the top of your page:
<?php
  session_start();
  .. rest of your code ..

-r-
Avatar of duta

ASKER

TO: Roonaan:

Thank you for coming back to help me again!

For some reason, the above prevent_multi_submit  scripts is not working. I put session_start() at the beginning of pages.

I spent almost entire day trying to figure out this and others, but none of them is working.

I am going to try them more tomorrow.

Thanks a lot!

duta