PHP code example of vicens / captcha
1. Go to this page and download the library: Download vicens/captcha library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vicens / captcha example snippets
composer
'providers' => [
// Other service providers...
\Vicens\Captcha\Providers\CaptchaServiceProvider::class
]
'aliases' => [
// Other facades...
'Captcha' => \Vicens\Captcha\Facades\Captcha::class
]
php artisan vendor:publish --provider=\Vicens\Captcha\Providers\CaptchaServiceProvider
return array(
/**
* 调试模式(不验证验证码的正确性), 设置为null时, 取值为app.debug
*
* @var bool|null
*/
'debug' => env('CAPTCHA_DEBUG', false),
/**
* 验证码的访问路径
*
* @var string
*/
'route' => '/captcha',
/**
* 路由名
*
* @var string
*/
'name' => 'captcha',
/**
* 中间件名,必须开启session
*
* @var string
*/
'middleware' => 'web',
/**
* 默认验证码长度
*
* @var int
*/
'length' => 4,
/**
* 验证码字符集
*
* @var string
*/
'charset' => 'abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789',
/**
* 是否开启严格模式(区分大小写)
*
* @var bool
*/
'strict' => false,
/**
* 默认验证码宽度
*
* @var int
*/
'width' => 150,
/**
* 默认验证码高度
*
* @var int
*/
'height' => 40,
/**
* 指定文字颜色
*
* @var string
*/
'textColor' => null,
/**
* 文字字体文件
*
* @var string
*/
'textFont' => null,
/**
* 指定图片背景色
*
* @var string
*/
'backgroundColor' => null,
/**
* 开启失真模式
*
* @var bool
*/
'distortion' => true,
/**
* 最大前景线条数
*
* @var int
*/
'maxFrontLines' => null,
/**
* 最大背景线条数
*
* @val int
*/
'maxBehindLines' => null,
/**
* 文字最大角度
*
* @var int
*/
'maxAngle' => 8,
/**
* 文字最大偏移量
*
* @var int
*/
'maxOffset' => 5
);
use \Vicens\Captcha\Facades\Captcha;
$image = Captcha::make();
$image = Captcha::setConfig($config)->make();
$image = Captcha::width(100)->height(40)->make();
$image->response();
$image->output();
Captcha::html($width, $height);
$image->getBase64();
$image->getDataUrl();
$image->getContent();
$image->save($filename);
Captcha::test($input);
Captcha::check($input);
Route::post('login','LoginController@login')->middleware(\Vicens\Captcha\Middleware\CaptchaMiddleware::class);
public function __constructor(){
$this->middleware(\Vicens\Captcha\Middleware\CaptchaMiddleware::class)->only(['login', 'register']);
}
$this->validation([
'code' => 'captcha'
]);
public function rules()
{
return [
'code' => 'captcha'
];
}
Captcha::url();
Captcha::src();
Captcha::image();
Captcha::clickableImage();