laravel-使用验证码
2017-08-08 16:08
337 查看
Laravel默认没有内置图片验证码功能,需要自己设置;
在Laravel中有很多图片验证码的库可以使用,本篇介绍其中之一:gregwar/captcha,这个库比较简单,在Laravel中比较常用。下面我们就来介绍下使用细节:
一、首先, composer.json中如下加入配置:
然后,已成习惯的命令:用cmd执行下面这条命令
composer update
二、在controller中使用:
在Laravel中有很多图片验证码的库可以使用,本篇介绍其中之一:gregwar/captcha,这个库比较简单,在Laravel中比较常用。下面我们就来介绍下使用细节:
一、首先, composer.json中如下加入配置:
"require": { ... "gregwar/captcha": "1.*" },
然后,已成习惯的命令:用cmd执行下面这条命令
composer update
二、在controller中使用:
//引用对应的命名空间 use Gregwar\Captcha\CaptchaBuilder; use Session; //图片验证码 public function captcha() { //生成验证码图片的Builder对象,配置相应属性 $builder = new CaptchaBuilder; //可以设置图片宽高及字体 $builder->build($width = 100, $height = 38, $font = null); //获取验证码的内容 $phrase = $builder->getPhrase(); //把内容存入session Session::flash('milkcaptcha', $phrase); //session()->flash('milkcaptcha',$phrase); //生成图片 header("Cache-Control: no-cache, must-revalidate"); header('Content-Type: image/jpeg'); $builder->output(); }三、页面中使用:
路由:Route::get('/yzm', 'UsersController@captcha')->name('yzm');
<div class="form-group"> <label for="password_confirmation">验证码:</label> <input type="password" name="password_confirmation" class="form-control" value="" style="width:100px"> <a href="javascript:void(0);"> <img src="{{ route('yzm') }}" onclick="javascript:this.src='{{ route('yzm') }}?tm='+Math.random()" width="100px" height="38px"> </a> </div>
相关文章推荐
- laravel框架学习之图形验证码的使用(四)
- laravel 使用验证码
- laravel中如何实现验证码验证及使用
- Laravel5.4中使用阿里大于(鱼)发送短信验证码
- Laravel5.2使用Captcha生成验证码实现登录(session巨坑)
- laravel5.2使用Captcha生成验证码(session巨坑)
- laravel中如何实现验证码验证及使用
- 使用 Captcha 扩展包 为 Laravel 5 应用生成验证码
- Laravel中使用Session存取验证码信息
- Laravel框架中验证码的使用
- laravel框架自带验证码使用
- yii 中的验证码使用中的问题解决
- Laravel使用php artisan migrate报错: [PDOException] SQLSTATE[42S02]: Base table or view not found: 114
- 在 Laravel 5.1 中使用 Pjax
- <开发总结>苹果ios 系统,使用自带浏览器safari,输入正确图形验证码一直报错!
- Laravel缓存的使用
- php--------ThinkPHP3.2验证码使用
- Laravel使用PHPQRCODE实现生成带有LOGO的二维码图片功能示例
- 使用kaptcha插件生成加法计算验证码
- Laravel开发之验证码