生成验证码的时候:
public function verify_c(){ $Verify = new ThinkVerify(); $Verify->fontSize = 18; $Verify->length = 4; $Verify->useNoise = false; $Verify->codeSet = '0123456789'; $Verify->imageW = 130; $Verify->imageH = 50; //$Verify->expire = 600; $Verify->entry(); }
<p class="top15 captcha" id="captcha-container"> <input name="verify" width="50%" height="50" class="captcha-text" placeholder="验证码" type="text"> <img width="30%" class="left15" height="50" alt="验证码" src="{:U('Home/Index/verify_c',array())}" title="点击刷新"> </p>
$(function () { var captcha_img = $('#captcha-container').find('img') var verifyimg = captcha_img.attr("src"); captcha_img.attr('title', '点击刷新'); captcha_img.click(function(){ if( verifyimg.indexOf('?')>0){ $(this).attr("src", verifyimg+'&random='+Math.random()); }else{ $(this).attr("src", verifyimg.replace(/?.*$/,'')+'?'+Math.random()); } }); })
验证在common.php中添加方法
function check_verify($code, $id = ""){ $verify = new ThinkVerify(); return $verify->check($code, $id); }
提交表单的时候:
$verify = I('param.verify',''); if(!check_verify($verify)){ $this->error("亲,验证码输错了哦!",$this->site_url,9); }