html
<?php
$ti=mt_rand(0,1000000);
Yii::app()->session['conn_id'] = $ti;
Yii::app()->session['conn']=$ti;
//echo Yii::app()->session['conn_id'];
?>
<input type="hidden" name="infoKey[code]" value="<?php echo Yii::app()->session['conn_id']; ?>"/><!--hidden-->
后台
$hide = $_POST['infoUser']['code'];
if ($hide == Yii::app()->session['conn']) {
//提交成功
else {
// echo "<script>alert('亲!就知道你会刷新提交,stop 你已经提交成功啦');</script>";
$this->redirect('./index.php?r=Sdkadd/register');
}
===========================================上面是Yii==============================================================================
1、提交页面
<?php
session_start();
$t=mktime();
$_SESSION['conn_id']=$t;
$_SESSION['conn']=$t;
var_dump($_SESSION);
var_dump($_COOKIE);
?>
<html>
<head>
<title>防止刷新提交或者重新提交</title>
</head>
<body>
<form method="POST" action="get.php">
<span>username:</span><input type="text" name="username" id="username"><br>
<input type="hidden" name="hidden" id="hidden" value="<?php echo $_SESSION['conn_id']?>">
<span>message:</span><input type="text" name="message" id="message"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
2、服务器端接收页面
<?php
session_start();
$username = $_POST['username']."<br>";
$message = $_POST['message'];
$hide = $_POST['hidden'];
var_dump($_SESSION);
if($hide==$_SESSION['conn'])
{
echo "亲,提交成功了哦";
}else
{
echo "<script>alert('亲!就知道你会刷新提交,stop 你已经提交成功啦');</script>";
echo "<script>window.location.href='index.php';</script>";
}
session_destroy();
?>
http://blog.sina.com.cn/s/blog_65f387740100z6xr.html