lookyman / recaptcha
此包已被废弃,不再维护。作者建议使用 contributte/recaptcha 包。
v1.0.2
2018-02-27 06:24 UTC
Requires
- php: >=5.5
- guzzlehttp/guzzle: ~6.0
- nette/di: ~2.3
- nette/forms: ~2.3
Requires (Dev)
- nette/robot-loader: ~2.3
- phpunit/phpunit: ~4.8
Conflicts
- nette/utils: 2.5.0
This package is not auto-updated.
Last update: 2022-02-01 12:50:52 UTC
README
此扩展提供了将 Google reCAPTCHA 集成到 Nette 框架中的功能。
要求
lookyman/ReCaptcha 需要 PHP 5.5 或更高版本。
安装
使用 Composer 是安装 lookyman/ReCaptcha 的最佳方式
$ composer require lookyman/recaptcha
您可以使用 neon 配置文件启用此扩展
extensions: recaptcha: lookyman\ReCaptcha\DI\ReCaptchaExtension
配置
此扩展创建了一个新的配置部分 recaptcha
,默认配置如下
recaptcha: siteKey: '' secretKey: '' verificationUrl: 'https://www.google.com/recaptcha/api/siteverify' errorMessage: 'You appear to be a bot' validateRemoteIp: off client: [] theme: 'light' type: 'image' size: 'normal'
您可以在 Google reCAPTCHA 管理页面获取您的 siteKey
和 secretKey
。
您可以通过 client
配置选项向默认的 Guzzle 客户端传递额外的设置。例如,如果您遇到 cURL 错误 60: SSL 证书问题:无法获取本地发行者证书
错误,您可以使用这里的 verify: off
选项来禁用对对等证书的验证。
此外,您需要将以下代码片段粘贴到模板中,在 </body>
标签关闭之前
<script src='https://www.google.com/recaptcha/api.js'></script>
用法
此扩展向 Nette\Forms\Container
命名空间添加了一个方法,其签名如下
/** * @param string $name Control name * @param string|NULL $label Control label * @return \lookyman\ReCaptcha\Forms\Controls\ReCaptchaControl */ public function addReCaptcha($name, $label = NULL);
将 reCAPTCHA 添加到您的表单与添加任何其他控件类型一样简单
protected function createComponentMyReCaptchaForm() { $form = new Nette\Application\UI\Form(); $form->addReCaptcha('recaptcha', 'You have to solve this before you send the form'); ... }
主页 https://lookyman.net 和仓库 https://github.com/lookyman/recaptcha。