IndexController.class.php
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
$this->display('index');//显示登陆界面
}
public function vcode(){
$config = array( 'fontSize' => 30, // 验证码字体大小
'length' => 5, // 验证码位数
' useNoise' => false, // 关闭验证码杂点
);
$Verify = new \Think\Verify($config);
$Verify->codeSet = '0123456789';
$Verify->entry(1);
}
public function check(){//判断要验证码
$vcode=I('vcode');
$verify = new \Think\Verify();
if($verify->check($vcode,1)){
$this->success('验证码正确',U('index'),'验证码正确');
}
else{ $this->success('验证码错误',U('index'),'验证码错误');}
}
}
index.html
<!DOCTYPE html>
<html>
<head>
<ti
<me
<js href="__PUBLIC__/js/jquery.min.js" />
<sc
$(function(){
if (localStorage.getItem('state') == 1) {
$("#vcode-img").attr('src','__URL__/vcode/random'+Math.random());
}
window.on
localStorage.setItem('state', 1)
};
$("#vcode-img").click(function(){
$("#vcode-img").attr('src','__URL__/vcode/random/'+Math.random());
});//实现点击验证码刷新
});
</sc
</head>
<body>
<form action="__URL__/check" method="post">
<p><label>验证码:<input type="text" name="vcode" id="vcode" ><img src="{:U('vcode')}" id="vcode-img"></label>
<p><label><input type="submit" value="验证"></label>
</form>
</body>
</html>
