The code below will help you to prevent multiple form submission from the users using PHP. First, create a web form as shown below.

<?php
session_start ();
?>
<!DOCTYPE html>
<html>
<head>
  <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<style>
*{box-sizing:border-box;}
body{font-family: 'Open Sans', sans-serif; color:#333; font-size:14px; background-color:#dadada; padding:100px;}
input{padding:5px; margin-bottom:5px; width:300px;}
</style>
<body>
  <?php
  if(isset($_POST['submit'])){
    if (!isset ( $_SESSION ['form_has_submitted'] )) {
     $_SESSION ['form_has_submitted'] = true;
   }
   if ($_SESSION ['form_has_submitted'] == true) {
     $_SESSION ['form_has_submitted'] = false;
     echo $_POST['usrname'];

   }else echo "Sorry! You have already submitted the form.";

  }else{
  ?>
  <form class="" action="" method="post">
    <h4>Please enter your name!</h4>
    <p>You are allowed to enter one time only. </p>
    <input type="text" name="usrname" /><br/>
    <input type="submit" value="Submit" name="submit">
  </form>
<?php }?>
</body>
</html>

Code Explanation

The code uses the session variable $_SESSION [‘form_has_submitted’] to keep track of the form submission. The code will check if the form has been submitted or not.
If not, it shows the form. Otherwise, it will check the session variable $_SESSION [‘form_has_submitted’]. If it has submitted for the first time ($_SESSION [‘form_has_submitted’] == true), it will set the value of the session variable to false and display the user’s name being submitted by the user.
If the value of the session variable is false, it describes the form has been submitted so there shouldn’t be any multiple submissions.

Recommande Reading

Last modified: March 18, 2019