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

dutaAsked:
Who is Participating?
 
RoonaanConnect With a Mentor Commented:
Hi,

You can do different things:
- Set a cookie
- Store the IP address in your database

-r-
0
 
dr_dedoCommented:
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!
0
 
dutaAuthor Commented:
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!

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
fehaCommented:
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
0
 
dutaAuthor Commented:
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
0
 
dutaAuthor Commented:
TO: feha:

Thanks again!

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

Thanks!

duta
0
 
dutaAuthor Commented:
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
    }
} */
?>
0
 
RoonaanCommented:
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-
0
 
dutaAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.