Home >php教程 >PHP源码 >【PHP】Web服务器端防止表单的重复提交

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

PHP中文网
PHP中文网Original
2016-05-25 17:16:011056browse

<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 [&#39;processing&#39;] )) {
  $_SESSION [&#39;processing&#39;] = false;
}
if ($_SESSION [&#39;processing&#39;] == false) {
  $_SESSION [&#39;processing&#39;] = true;
    //validation 
  if ($file = fopen ( "test.txt", "w+" )) {
    fwrite ( $file, "Processing" );
  } else {
    echo "Error opening file.";
  }
  echo $_POST [&#39;yourname&#39;];
  unset ( $_SESSION [&#39;processing&#39;] );
}
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn