• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

time delay in submitting form

how would i prevent user from submitted a form to much inside a time period.

eg. only allow them submit the form say 1 with a 2 min period.  if user trys to submit form within these 2 mins, stop them.. etc etc
0
ellandrd
Asked:
ellandrd
  • 2
1 Solution
 
RoonaanCommented:
You would have to put a timestamp in your database/session and compare with $now:

$lastSubmit = isset($_SESSION['lastSubmit']) ? $_SESSION['lastSubmit'] : 0;
$limit = strtotime('-2 minutes');
if($lastSubmit > $limit) {
  usleep(2000); //wait 2 seconds to prevent bots from detecting flooddetection too easily
  exit('Flood detection: You are not allowed to submit a form within 2 minutes of your last submit');
} else {
  $_SESSION['lastSubmit'] = mktime();
}

-r-
0
 
ellandrdAuthor Commented:
im not using a database. its just a simple PHP page with a form that displays the info that you submitted...

will the above till work?
0
 
RoonaanCommented:
The above uses session rather than database. If you allow sessions it will work.
Alternatively you could set a cookie of course. But that can be deleted by the end user.

-r-
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now