php防止表单重复提交代码
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记录表单是否被处理过。如果显示表单已经处理过,则不再处理。
精彩图集
精彩文章






