time delay in submitting form

Posted on 2006-05-20
Last Modified: 2010-05-18
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
Question by:ellandrd
    LVL 49

    Accepted Solution

    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();

    LVL 16

    Author Comment

    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?
    LVL 49

    Expert Comment

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    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 …
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    The viewer will learn how to count occurrences of each item in an array.
    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…

    759 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

    10 Experts available now in Live!

    Get 1:1 Help Now