验证码输出
function image(){
//给验证码配置
$cfg = array(
'imageH' => 45,
...//别的配置
);
// 实例化Verify类
$very = new \Think\Verify($cfg);//完全限定名称方式
$very -> entry();//输出验证码
}
显示验证码
<img src = "{$smarty.const.__CONTROLLER__}/image" onclick = "this.src = {$smarty.const.__CONTROLLER__}/image/"+ Math.random() alt = ""/>
验证码校验
function login(){
if (!empty($_POST)) {
$vry = new \Think\Verify();
if ($vry -> check($_POST['captcha'])) {
echo "验证码正确";
}else{
echo "验证码错误";
}
}
}