yhbyun / laravel-securimage
Laravel 5 Securimage 辅助工具
v0.2.4
2021-05-11 07:02 UTC
Requires
- php: >=5.5.0
- dapphp/securimage: 3.6.8
- illuminate/support: ~5.0|~6.0|~7.0|~8.0
Requires (Dev)
- mockery/mockery: ~0.9.4
- orchestra/testbench: 3.1.*
- phpunit/phpunit: ~4.0
README
这是一个简单的 Laravel 5 包装包,用于 Securimage。
安装
通过运行以下命令将包添加到您的 composer.json
composer require yhbyun/laravel-securimage
安装完成后,将其添加到 config/app.php 中的提供者列表
Yhbyun\Securimage\SecurimageServiceProvider::class,
将资源发布到您的公共文件夹
$ php artisan vendor:publish --provider="Yhbyun\Securimage\SecurimageServiceProvider"
配置
config/securimage.php
return [ 'length' => env('SECURIMAGE_LENGTH', 6), 'width' => env('SECURIMAGE_WIDTH', 215), 'height' => env('SECURIMAGE_HEIGHT', 80), 'perturbation' => env('SECURIMAGE_PERTURBATION', .85), 'case_sensitive' => env('SECURIMAGE_CASE_SENSITIVE', false), 'num_lines' => env('SECURIMAGE_NUM_LINES', 0), 'charset' => env('SECURIMAGE_CHARSET', 'ABCDEFGHKLMNPRSTUVWYZabcdefghklmnprstuvwyz23456789'), 'signature' => env('SECURIMAGE_SIGNATURE', 'ecplaza'), 'show_text_input' => env('SECURIMAGE_SHOW_TEXT_INPUT', false), ];
示例用法
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())
{
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><button type="submit" name="check">Check</button></p>';
$form .= '</form>';
return $form;
});
测试
$ phpunit --stderr
