龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php防止表单重复提交代码

时间:2014-06-18 20:47来源:网络整理 作者:网络 点击:
分享到:
php防止表单重复提交代码 **php代码**```{.php}lt;htmlgt;lt;bodygt;lt;form action=quot;index.phpquot; method=quot;postquot;gt;lt;input type=quot;hiddenquot; name=quot;submittedquot; value=quot;yesquot; /gt; Your Name: lt;input type=

php代码

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

是通过session记录表单是否被处理过。如果显示表单已经处理过,则不再处理。

精彩图集

赞助商链接