Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP survey form and block multiple submissions

Posted on 2006-06-11
12
Medium Priority
?
728 Views
Last Modified: 2008-01-09
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

0
Comment
Question by:duta
  • 5
  • 2
  • 2
  • +1
12 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 1000 total points
ID: 16881634
Hi,

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

-r-
0
 
LVL 16

Expert Comment

by:dr_dedo
ID: 16881658
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
 

Author Comment

by:duta
ID: 16881659
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:feha
ID: 16882177
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
 

Author Comment

by:duta
ID: 16882190
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
 
LVL 2

Assisted Solution

by:feha
feha earned 1000 total points
ID: 16882191
0
 

Author Comment

by:duta
ID: 16882198
TO: feha:

Thanks again!

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

Thanks!

duta
0
 

Author Comment

by:duta
ID: 16882968
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
 
LVL 49

Expert Comment

by:Roonaan
ID: 16883255
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
 

Author Comment

by:duta
ID: 16883283
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question