Prevent form from being submitted twice

后端 未结 4 1641
孤城傲影
孤城傲影 2020-12-10 06:23

I have a simple php form, like this:

the problem is that if

相关标签:
4条回答
  • 2020-12-10 06:25

    In the case of user having lag and he hits the submit button a few times, then maybe use client side mechanism, use js to set the submit button to disabled once it is clicked. but will have to display message saying roughly something like, "sending message ... if no response pls reload page and retry".

    0 讨论(0)
  • 2020-12-10 06:37

    Perform a redirect after the data is inserted to a confirmation page (can be done with header(), which should clear out the POST data and allow for refreshing without duplicating content.

    0 讨论(0)
  • 2020-12-10 06:44
    session_start();    
    if (!$_SESSION['REQUEST_TYPE_USER_ID'] == $_POST)
    {
    //your code
    //after the success process
        $_SESSION['REQUEST_TYPE_USER_ID'] = $_POST;
    }
    else
    {
    // request duplicated
    }
    
    0 讨论(0)
  • 2020-12-10 06:46

    You should perform a REDIRECT to a page with a message that the data was inserted... and a back button to go to the form again (if you want to)...

    To redirect using PHP use the header function:

    header('Location: http://www.example.com/');
    
    0 讨论(0)
提交回复
热议问题