(1) PHP part
session_start(); $sign=$_SESSION['code']; $sscode=mt_rand(0,1000000); $this->assign("sscode",$sscode);//将随机值传入html中 if(isset($_POST['submit'])){ //isset($_POST['submit'])为判断是否有表单提交 //$_POST['submit_sign']为表单中隐藏域的一个值 if($_POST['submit_sign']==$sign){ //处理表单数据 } else{ echo "<script>alert('请勿重复提交表单')</script>" } }</span>
(2) HTML part
<form action="" name="myform" method="post"> <input type="submit" value="提交" name="submit"/> <input type="hidden" value="<?php echo $sscode?>" name=submit_sign/><!--隐藏域--> </form></span>
The above introduces the use of session in PHP to avoid repeated submission of forms when refreshing the page, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.