标签:验证码 zhinkphp
在控制器中:
/**
* 输出验证码
*/
public function getverify(){
$VModle=new \Think\Verify();
$VModle->codeSet=‘0123456789‘;
$VModle->length=4;
$VModle->entry();
}在页面中的html
<input type="text" name="verify" placeholder="验证码" class="form-control" style="width:100px;float: left;">
<img id="verifyimg" src="{:U(‘Public/getverify‘)}" width="100">javacsript即时刷新
$("#verifyimg").click(function() {
var verifyURL = "{:U(‘Public/getverify‘, ‘‘, ‘‘)}";
var time = new Date().getTime();
$(this).attr({"src" : verifyURL+"/"+time});
});异步验证是否正确:
/**
* 异步验证验证码是否正确
* @params verify;
*/
public function ajaxcheckverify(){
if(!IS_POST){
$data[‘status‘] = 0;
}
else{
$VModle=new \Think\Verify();
$code = trim(I(‘verify‘));
if(!$VModle->check($code)){
$data[‘status‘] = 0;
$data[‘data‘] = $code;
}
else{//验证成功
$data[‘status‘] = 1;
}
}
echo json_encode($data);
}本文出自 “芭菲雨的博客” 博客,请务必保留此出处http://bafeiyu.blog.51cto.com/5401101/1607492
标签:验证码 zhinkphp
原文地址:http://bafeiyu.blog.51cto.com/5401101/1607492