Solved

PHP survey form and block multiple submissions

Posted on 2006-06-11
12
689 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 250 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 2

Assisted Solution

by:feha
feha earned 250 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now