Click to See Complete Forum and Search --> : not letting someone submit a form more then once
esthera
06-08-2004, 02:03 PM
I have a form and the problem is people are submitting then pressing the back key and submitting again.
What is the best way to stop this?
Should I check their IP?
Should I set a session variable?
Can we disable the back button or make the form empty on clicking back?
What do you suggest and how would I do it? (the form submits to a php page)
96turnerri
06-08-2004, 03:11 PM
you could make it method=post so it expires, log there ip would be the best bet on the form action script use this
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$handle = @fopen("ips.txt", "a");
if(!$handle)
{die("Error opening file to writing");}
fwrite($handle, $ip."\n");
fclose($handle);
?>
and on form page
use this
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$iplist = file_get_contents('ips.txt');
if(preg_match("/\b".$ip."\b/", $iplist)) {
echo "Sorry you have already submitted this form";
} else {
//Form code or include
}
?>
96turnerri
06-08-2004, 03:14 PM
o yes and if the form page is not php
use this in form action script
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$iplist = file_get_contents('ips.txt');
if(preg_match("/\b".$ip."\b/", $iplist)) {
echo "Sorry you have already submitted this form";
} else {
$handle = @fopen("ips.txt", "a");
if(!$handle)
{die("Error opening file to writing");}
fwrite($handle, $ip."\n");
fclose($handle);
//current form action script
}
?>
Hope this helps