<?php
session_start();
header("Content-Type:text/html;charset:utf8");
function set_token(){
$_SESSION['token']=md5(microtime(true)); }
function valid_token(){
$return=$_REQUEST['token']==$_SESSION['token']? true:false;
set_token();
return $return;
}
//如果token为空,则生成一个token
if(!isset($_SESSION['token'])||($_SESSION['token']=="")){
set_token();
}
if(isset($_POST['web'])){
if(!valid_token()){
echo "请不要重复提交";
}else{
echo "提交成功,value:".$_POST['web'];
} }else{
?>
<center>
<form method="post" action="">
<input type="hidden" name="token" value="<?php echo $_SESSION['token'] ?>" />
<input type="text" class="input" name="web" value="www.baidu.com" />
<input type="submit" class="btn" value="提交" />
</form>
</center>
<?php
}
?>