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

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

PHP中文网
PHP中文网原创
2016-05-25 17:16:011024浏览

<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;] );
}
?>


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn