TP框架设置验证码
thinkphp框架有专门的的验证码生成的模块
public function shengcheng(){
$n = new \Think\Verify();
$n->entry();
}
下面是验证模块:
public function ceshi(){
if(!IS_POST)
{
$this->show();
}
else
{
$yzm = I('post.yzm');
$config = array(
'reset' => false // 验证成功后是否重置,这里才是有效的。
);
$n = new \Think\Verify($config);
if($n->check($yzm))
{
$this->ajaxReturn("y","eval");
}
else
{
$this->ajaxReturn("n","eval");
}
}
}
前台界面:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="__PUBLIC__/jquery-1.11.2.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<img src="__CONTROLLER__/shengcheng"/>
<input type="text" id="yzm" />
</body>
<script type="text/javascript">
$("#yzm").blur(function(){
var yzm = $(this).val();
$.ajax({
type:"post",
url:"__ACTION__",
data:{yzm:yzm},
dataType:"TEXT",
success:function(r){
alert(r);
}
});
})
</script>
</html>

浙公网安备 33010602011771号