欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

【PHP】Web服务器端防止表单的重复提交

程序员文章站 2022-06-17 15:03:33
...
<html>
<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'] );
}
?>