1 <?php 2 session_start(); 3 header("Content-Type:text/html;charset:utf8"); 4 function set_token(){ 5 $_SESSION['token']=md5(microtime(true)); 6 7 } 8 function valid_token(){ 9 $return=$_REQUEST['token']==$_SESSION['token']? true:false; 10 set_token(); 11 return $return; 12 } 13 //如果token为空,则生成一个token 14 if(!isset($_SESSION['token'])||($_SESSION['token']=="")){ 15 set_token(); 16 } 17 if(isset($_POST['web'])){ 18 if(!valid_token()){ 19 echo "请不要重复提交"; 20 }else{ 21 echo "提交成功,value:".$_POST['web']; 22 } 23 24 }else{ 25 ?> 26 <center> 27 <form method="post" action=""> 28 <input type="hidden" name="token" value="<?php echo $_SESSION['token'] ?>" /> 29 <input type="text" class="input" name="web" value="www.baidu.com" /> 30 <input type="submit" class="btn" value="提交" /> 31 </form> 32 </center> 33 <?php 34 } 35 ?>