index.php
当前表单页面is_submit设为0
SESSION_START();
$_SESSION['is_submit'] = 0;
<form id="reg" action="post.php" method="post">
<p>用户名:<input type="text" class="input" name="username" id="user"></p>
<p>密 码:<input type="password" class="input" name="password" id="pass"></p>
<p>E-mail:<input type="text" class="input" name="email" id="email"></p>
<p><input type="submit" name="submit" class="btn" value="提交注册"/></p>
</form>
post.php
若是提交表单了,设当前'is_submit为1,若是刷新post.php,那么将执行else代码
SESSION_START();
if (isset($_POST['submit'])) {
if ($_SESSION['is_submit'] == '0') {
$_SESSION['is_submit'] = '1';
echo "代码块,要做的事,代码...<a onclick='history.go(-1);' href='javascript:void(0)'>返回</a>";
} else {
echo "请不用重复提交<a href='index.php'>PHP+SESSION防止表单重复提交</a>";
}
}