gremo/captcha-form-bundle
Composer 安装命令:
composer require gremo/captcha-form-bundle
包简介
Symfony bundle that provides CAPTCHA form field and supports multiple adapters.
关键字:
README 文档
README
Symfony bundle that provides CAPTCHA form field to solve challenge-response tests. Supports multiple adapters as well as custom ones. Built-in adapter for:
New contributors are welcome!
Installation
composer require gremo/captcha-form-bundle
Then enable the bundle:
<?php // config/bundles.php return [ // ... Gremo\CaptchaFormBundle\GremoCaptchaFormBundle::class => ['all' => true], ];
If you are using a previous version of Symfony:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Gremo\CaptchaFormBundle\GremoCaptchaFormBundle(), ); }
Configuration
gremo_captcha_form: # Default template, change only if you know what your are doing template: 'GremoCaptchaFormBundle::default.html.twig' # Default adapter (default to the first adapter) default_adapter: ~ # Adapters (one or more) configuration adapters: # Adapter key and its options adapter_key1: [] # ... and another adapter adapter_key2: []
In order to use the CAPTCHA form you need to configure at least one adapter (see "Adapters" section).
Usage
You can use the generic form type instead of the form provided by each adapter. This is more maintainable as you depends only on one form type.
The generic type use the default adapter and options provided in the configuration. An example usage:
// For Symfony >= 2.8 and PHP >= 5.5 use the class name resolution via ::class use Gremo\CaptchaFormBundle\Form\Type\CaptchaType; $builder->add('captcha', CaptchaType::class, [ // Pass custom options to override defaults from configuration ]); // For Symfony >= 2.8 and PHP < 5.5 use the fully-qualified class name as string $builder->add('captcha', 'Gremo\CaptchaFormBundle\Form\Type\CaptchaType', [ // Pass custom options to override defaults from configuration ]); // For Symfony < 2.8 $builder->add('captcha', 'gremo_captcha', [ // Pass custom options to override defaults from configuration ]);
Adapters
At least one adapter must be configured.
Google reCAPTCHA v2 adapter
Adapter key: recaptcha Form Type: Gremo\CaptchaFormBundle\Form\Type\RecaptchaType
Add the google/recaptcha library to your project:
composer require google/recaptcha^1
Configure the adapter (options explanation):
# ... adapters: # ... recaptcha: # Mandatory options key: ~ # string secret: ~ # string # Not mandatory options theme: ~ # string type: ~ # string size: ~ # string tabindex: ~ # integer callback: ~ # string expired_callback: ~ # string
Finally, add the reCAPTCHA <script> tag to your base template:
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
Tip: add the
hlparameter to the script in order to localize the CAPTCHA, i.e. in Twighl={{ app.request.locale }}.
Example usage:
// For Symfony >= 2.8 and PHP >= 5.5 use the class name resolution via ::class use Gremo\CaptchaFormBundle\Form\Type\RecaptchaType; $builder->add('captcha', RecaptchaType::class, [ // Pass custom options to override defaults from configuration ]); // For Symfony >= 2.8 and PHP < 5.5 use the fully-qualified class name as string $builder->add('captcha', 'Gremo\CaptchaFormBundle\Form\Type\RecaptchaType', [ // Pass custom options to override defaults from configuration ]); // For Symfony < 2.8 $builder->add('captcha', 'gremo_captcha_recaptcha', [ // Pass custom options to override defaults from configuration ]);
Google reCAPTCHA v3 adapter
Adapter key: recaptcha_v3 Form Type: Gremo\CaptchaFormBundle\Form\Type\RecaptchaV3Type
Add the google/recaptcha library to your project:
composer require google/recaptcha^1
Configure the adapter (options explanation):
# ... adapters: # ... recaptcha_v3: # Mandatory options key: ~ # string secret: ~ # string # Not mandatory options score_threshold: ~ # float
There is no need to add any <script> tag because the form theme will do it for you.
Example usage:
// For Symfony >= 2.8 and PHP >= 5.5 use the class name resolution via ::class use Gremo\CaptchaFormBundle\Form\Type\RecaptchaV3Type; $builder->add('captcha', RecaptchaV3Type::class, [ // For options ]); // For Symfony >= 2.8 and PHP < 5.5 use the fully-qualified class name as string $builder->add('captcha', 'Gremo\CaptchaFormBundle\Form\Type\RecaptchaV3Type', [ // For options ]); // For Symfony < 2.8 $builder->add('captcha', 'gremo_captcha_recaptcha_v3', [ // For options ]);
Gregwar captcha adapter
Adapter key: gregwar_captcha Form Type: Gremo\CaptchaFormBundle\Form\Type\GregwarCaptchaType
Add the gregwar/recaptcha library to your project:
composer require gregwar/recaptcha^1
Configure the adapter (options explanation):
# ... adapters: # ... gregwar_captcha: # Not mandatory options storage_key: _gregwar_captcha width: ~ # integer height: ~ # integer quality: ~ # integer font: ~ # string distorsion: ~ # boolean interpolation: ~ # boolean ignore_all_effects: ~ # boolean orc: ~ # boolean
Example usage:
// For Symfony >= 2.8 and PHP >= 5.5 use the class name resolution via ::class use Gremo\CaptchaFormBundle\Form\Type\GregwarCaptchaType; $builder->add('captcha', GregwarCaptchaType::class, [ // Pass custom options to override defaults from configuration ]); // For Symfony >= 2.8 and PHP < 5.5 use the fully-qualified class name as string $builder->add('captcha', 'Gremo\CaptchaFormBundle\Form\Type\GregwarCaptchaType', [ // Pass custom options to override defaults from configuration ]); // For Symfony < 2.8 $builder->add('captcha', 'gremo_captcha_gregwar', [ // Pass custom options to override defaults from configuration ]);
Honeypot adapter
Adapter key: honeypot Form Type: Gremo\CaptchaFormBundle\Form\Type\HoneypotType
Configure the adapter:
# ... adapters: # ... honeypot: # Mandatory options type: ~ # string, "text" or "hidden" or their FQCN (Symfony >= 2.8)
Example usage:
// For Symfony >= 2.8 and PHP >= 5.5 use the class name resolution via ::class use Gremo\CaptchaFormBundle\Form\Type\HoneypotType; $builder->add('captcha', HoneypotType::class, [ // Pass custom options to override defaults from configuration ]); // For Symfony >= 2.8 and PHP < 5.5 use the fully-qualified class name as string $builder->add('captcha', 'Gremo\CaptchaFormBundle\Form\Type\HoneypotType', [ // Pass custom options to override defaults from configuration ]); // For Symfony < 2.8 $builder->add('captcha', 'gremo_captcha_honeypot', [ // Pass custom options to override defaults from configuration ]);
gremo/captcha-form-bundle 适用场景与选型建议
gremo/captcha-form-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.07k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 02 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「recaptcha」 「spam」 「captcha」 「bot」 「Abuse」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gremo/captcha-form-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gremo/captcha-form-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gremo/captcha-form-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple captcha generator
reCAPTCHA library
Client library for reCAPTCHA with proxy support, a free service that protects websites from spam and abuse.
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
A simple and easy to use Google ReCaptcha v3 package for Laravel
Two Captcha
统计信息
- 总下载量: 15.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: ISC
- 更新时间: 2016-02-28