通过 后台->系统->系统设置->图像验证码
实现在线设置验证码的生成规则,以快速调整系统验证策略。
定义了一些常见用法方便使用,可以满足大部分常用场景。
\BusyPHP\Captcha // 验证码类
\BusyPHP\facade\Captcha // 验证码工厂类
use \BusyPHP\facade\Captcha;
class CaptchaController {
public function index() {
return Captcha::id('login')->width(100)->height(40)->response();
}
}
use \BusyPHP\facade\Captcha;
class CaptchaController {
public function index() {
return '<img src="'. Captcha::id('login')->url() .'"/>';
}
}
use \BusyPHP\facade\Captcha;
use \BusyPHP\exception\VerifyException;
try {
Captcha::id('login')->check(input('post.code'));
} catch (VerifyException $e) {
$e->getMessage();
// 未输入验证码
$e->getField() == Captcha::VERIFY_EMPTY_CODE;
// 验证码错误
$e->getField() == Captcha::VERIFY_ERROR;
// 验证码过期
$e->getField() == Captcha::VERIFY_EXPIRE;
}
use \BusyPHP\facade\Captcha;
Captcha::id('login')->clear();