Solved

PHP survey form and block multiple submissions

Posted on 2006-06-11
12
717 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

623 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