php防止快速刷屏留言



刚开始自然就想到了js 的 settimeout。后来觉得还是php自己的session方便些。

直接代码如下:

//防刷屏控制if(isset($_SESSION["allowpostTime"])&&(time()-$_SESSION["allowpostTime"]<8)){//前台说是说5秒,后台实际控制8秒echo2;}else{$msg=$adverSer->Filter_Keywords($_POST['msg']);$ret=$proObj->addmsg($openid,$msg);if($ret){$_SESSION["allowpostTime"]=time();echo1;}else{unset($_SESSION["allowpostTime"]);echo0;}}




参考资料:

http://blog.sina.com.cn/s/blog_48c61da6010008vm.html