Sunday, 18 March 2018

PHP Prevent submit until some time

To prevent submission of form or any script we can use PHP Session to prevent concurrent submission.

if (isset($_POST) && !empty($_POST)) 
{
    if (isset($_SESSION['posttimer']))
    {
        if ( (time() - $_SESSION['posttimer']) <= 2)
        {
            // less then 2 seconds since last post
        }
        else
        {
            // more than 2 seconds since last post
        }
    }
    $_SESSION['posttimer'] = time();
}

No comments:

Post a Comment