//控制器
//提交确认
public function logincl() {
$verCode = trim(I('post.verCode'));//驗證碼
if(!$this->check_verify($verCode)){
die("<script>alert('驗證碼錯誤,請刷新驗證碼!');history.back(-1);</script>");
}
}
//验证码验证
function check_verify($code){
$verify = new \Think\Verify();
return $verify->check($code);
}
//验证码生成 -》点击图片更换验证码
function verify() {
$config = array(
'fontSize' => 16, // 驗證碼字體大小
'length' => 5, // 驗證碼位數
'useCurve' => false, // 關閉驗證碼雜點
'useCurve' => false,
);
$Verify = new \Think\Verify($config);
$Verify->codeSet = '0123456789';
$Verify->entry();
}
//前端页面
<tr>
<td width="42%"><input name="verCode" id="verCode" type="text" class="loginuser1" onclick="JavaScript:this.value=''"/> </td>
<td width="58%"> <img src="/admin.php/Home/login/verify" name="myHeader" height="35" id="myHeader" onClick="this.src='/admin.php/Home/login/verify?'+Math.random();" /></td>
</tr>