1)php.ini需要开两个扩展
extension=php_fileinfo.dll
extension=php_gd2.dll
2)使用composer安装类包
composer require mews/captcha
3)配置文件里添加服务及服务别名(门面)
'providers' => [ // ... Mews\Captcha\CaptchaServiceProvider::class,]'aliases' => [ // ... 'Captcha' => Mews\Captcha\Facades\Captcha::class,]
4)生成验证图片
1、直接生成图片
captcha();
2、返回验证码图片url
captcha_src();
3、返回html(img标签)
captcha_img();
5)验证码验证
$rules = ['captcha' => 'required|captcha'];$validator = Validator::make(Input::all(), $rules);if ($validator->fails()){ echo 'Incorrect!
';}else{ echo 'Matched :)
';}
via: