/    Sign up×
Community /Pin to ProfileBookmark

not letting someone submit a form more then once

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)

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriJun 08.2004 — you could make it method=post so it expires, log there ip would be the best bet on the form action script use this
[code=php]
<?php

$ip = $_SERVER['REMOTE_ADDR'];

$handle = @fopen("ips.txt", "a");
if(!$handle)
{die("Error opening file to writing");}
fwrite($handle, $ip."n");
fclose($handle);

?>[/code]


and on form page

use this
[code=php]
<?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
}

?>[/code]
Copy linkTweet thisAlerts:
@96turnerriJun 08.2004 — o yes and if the form page is not php

use this in form action script

[code=php]
<?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
}

?>[/code]


Hope this helps
×

Success!

Help @esthera spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...