laravel 图像验证码 Gregwar\\Captcha 和 mews/captcha
2017-02-20 13:55
726 查看
工具:
1. The PHP Package Repository( PHP 包仓库): https://packagist.org
2. Laravel Framework version 5.2.45
一. mews/captcha
http://laravelacademy.org/post/3910.html
1.安装
composer require mews/captcha (安装最新的版本 , 指定版本composer require mews/captcha=2.1.0)
或
在composer.json中:
"require": {
"laravel/framework": "5.2.*",
"mews/captcha": "^2.1"
}
注意:
In Windows, you'll need to include the GD2 DLL
an extension in php.ini.(打开gd2扩展)
2.配置
使用Captcha服务提供者之前还需要在
同时注册下相应门面:
如果要使用自定义的配置,还可以发布配置文件到
编辑新生成的
注:生成时出现错误:( 然后是手动创建的 captcha.php 文件)
[League\Flysystem\Exception]
Impossible to create the root directory "".
-----------------------------------------------分割------------------------------------------------------
4.示例
如果要返回原生图片,可以调用这个函数:
或者
如果要返回URL:
或者
如果要返回HTML:
我们这个示例中使用的就是这个函数,或者调用
要使用配置文件
二. Gregwar\\Captcha
参考:http://www.jianshu.com/p/8e4ac7852b5a
1.安装
composer require gregwar/captcha
之后在composer.json文件中加入自动加载:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Gregwar\\Captcha\\": "vendor/Captcha/"
}
},
然后运行composer dump-autoload --optimize 命令
使用gregwar/captcha库:
$builder = new CaptchaBuilder;
$builder->build(150,32);
\Session::set('phrase',$builder->getPhrase()); //存储验证码
return response($builder->output())->header('Content-type','image/jpeg');
1. The PHP Package Repository( PHP 包仓库): https://packagist.org
2. Laravel Framework version 5.2.45
一. mews/captcha
http://laravelacademy.org/post/3910.html
1.安装
composer require mews/captcha (安装最新的版本 , 指定版本composer require mews/captcha=2.1.0)
或
在composer.json中:
"require": {
"laravel/framework": "5.2.*",
"mews/captcha": "^2.1"
}
执行
composer install
注意:
In Windows, you'll need to include the GD2 DLL
php_gd2.dllas
an extension in php.ini.(打开gd2扩展)
2.配置
使用Captcha服务提供者之前还需要在
config/app.php中注册服务提供者:
'providers' => [ Mews\Captcha\CaptchaServiceProvider::class, ]
同时注册下相应门面:
'aliases' => [ 'Captcha' => Mews\Captcha\Facades\Captcha::class, ]
如果要使用自定义的配置,还可以发布配置文件到
config目录:
$ php artisan vendor:publish
编辑新生成的
captcha.php:
return [ 'default' => [ 'length' => 5, 'width' => 120, 'height' => 36, 'quality' => 90, ], // ... ];
注:生成时出现错误:( 然后是手动创建的 captcha.php 文件)
[League\Flysystem\Exception]
Impossible to create the root directory "".
-----------------------------------------------分割------------------------------------------------------
4.示例
// app/Http/routes.php Route::any('captcha-test', function() { if (Request::getMethod() == 'POST') { $rules = ['captcha' => 'required|captcha']; $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { 4000 echo '<p style="color: #ff0000;">Incorrect!</p>'; } else { echo '<p style="color: #00ff30;">Matched :)</p>'; } } $form = '<form method="post" action="captcha-test">'; $form .= '<input type="hidden" name="_token" value="' . csrf_token() . '">'; $form .= '<p>' . captcha_img() . '</p>'; $form .= '<p><input type="text" name="captcha"></p>'; $form .= '<p><button type="submit" name="check">Check</button></p>'; $form .= '</form>'; return $form; });
如果要返回原生图片,可以调用这个函数:
captcha();
或者
Captcha::create();
如果要返回URL:
captcha_src();
或者
Captcha::src();
如果要返回HTML:
captcha_img();
我们这个示例中使用的就是这个函数,或者调用
Captcha门面上的方法:
Captcha::img();
要使用配置文件
captcha.php中不同的配置项,可以这样调用:
captcha_img('flat'); Captcha::img('inverse');
二. Gregwar\\Captcha
参考:http://www.jianshu.com/p/8e4ac7852b5a
1.安装
composer require gregwar/captcha
之后在composer.json文件中加入自动加载:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Gregwar\\Captcha\\": "vendor/Captcha/"
}
},
然后运行composer dump-autoload --optimize 命令
使用gregwar/captcha库:
$builder = new CaptchaBuilder;
$builder->build(150,32);
\Session::set('phrase',$builder->getPhrase()); //存储验证码
return response($builder->output())->header('Content-type','image/jpeg');
相关文章推荐
- Laravel的验证码库gregwar/captcha
- Laravel验证码工具gregwar/captcha
- Laravel的验证码库gregwar/captcha
- Laravel验证码类库: gregwar/captcha
- Laravel验证码工具gregwar/captcha
- Laravel的验证码库gregwar/captcha
- Laravel的验证码库gregwar/captcha
- Laravel的验证码库gregwar/captcha
- laravel整合mews captcha验证码的时候只出现两条边框,没有文字和背景图片
- Laravel-5.1验证码mews captcha
- laravel 图片验证码 mews/captcha
- 使用 Captcha 扩展包 为 Laravel 5 应用生成验证码
- Laravel-5.1 ---- 将mews captcha整合到项目中!
- Laravel - 验证码(captcha)
- Laravel5 验证码Captcha 扩展
- laravel5.2使用Captcha生成验证码(session巨坑)
- Laravel-5.1 ---- 将mews captcha整合到项目中!
- Laravel ---- 将mews captcha整合到项目中!
- laravel 5.5 登录验证码 captcha 引入
- Laravel5.2使用Captcha生成验证码实现登录(session巨坑)