qing7777 / captcha
Hyperf Captcha Package
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 1
Open Issues: 0
Type:package
Requires
- php: >=7.2
- ext-gd: *
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~4.1
This package is auto-updated.
Last update: 2025-03-29 00:47:58 UTC
README
Require this package with composer:
composer require qing7777/captcha
Configuration
To use your own settings, publish config.
php bin/hyperf.php vendor:publish qing7777/captcha
config/autoload/captcha.php
return [ 'default' => [ 'length' => 5, 'width' => 120, 'height' => 36, 'quality' => 90, 'math' => true, //Enable Math Captcha ], // ... ];
Example Usage
// [your site path]/Http/routes.php Route::any('captcha-test', function() { if (request()->getMethod() == 'POST') { $rules = ['captcha' => 'required|captcha']; $validator = validator()->make(request()->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><input type="text" name="captcha"></p>'; $form .= '<p><button type="submit" name="check">Check</button></p>'; $form .= '</form>'; return $form; });
Return Image
captcha();
or
Captcha::create();
Return URL
captcha_src();
or
Captcha::src();
Return HTML
captcha_img();
or
Captcha::img();
To use different configurations
captcha_img('flat'); Captcha::img('inverse');