Prevent Multiple Submissions on the Server Side in PHP

Description

The following code shows how to prevent Multiple Submissions on the Server Side.

Example


<html>//from  w  w w .  ja  v a  2  s  . c  o  m
<body>
<form action="index.php" method="post">
<input type="hidden" name="submitted" value="yes" /> Your Name: <input
  type="text" name="yourname" maxlength="150" /><br />
<input type="submit" value="Submit" style="margin-top: 10px;" /></form>
</body>
</html>
<?php
session_start ();
if (! isset ( $_SESSION ['processing'] )) {
  $_SESSION ['processing'] = false;
}
if ($_SESSION ['processing'] == false) {
  $_SESSION ['processing'] = true;
    //validation 
  if ($file = fopen ( "test.txt", "w+" )) {
    fwrite ( $file, "Processing" );
  } else {
    echo "Error opening file.";
  }
  echo $_POST ['yourname'];
  unset ( $_SESSION ['processing'] );
}
?>




















Home »
  PHP Tutorial »
    Form »




PHP Form
Form Demo