composer require mews/captcha
详情可见 :captcha链接
PHP
在config/app.php下配置
'providers' => [
// ...
Mews\Captcha\CaptchaServiceProvider::class,
]
'aliases' => [
// ...
'Captcha' => Mews\Captcha\Facades\Captcha::class,
]
php artisan vendor:publish?
选择与config对应的数字
config下创建captcha.php
return [
'default' => [
'length' => 5, //验证码长度
'width' => 120, //图片宽
'height' => 36, //图片长
'quality' => 90,
'math' => true, //是否使用数字算法,可以删掉!!!
'expire' => 60, //Stateless/API captcha expiration
],
// ...
];
html
<img src="{{ captcha_src() }}" id="captcha" >
<input type='text' name='captcha'>
js
点击切换验证码
<script>
$('#captcha').click(function(){
$(this).prop('src',"{{captcha_src()}}"+Math.random(1000,9999));
})
</script>
后端验证
'captcha'=>'required|captcha'
|