noylecorp/laravel-recaptcha
Composer 安装命令:
composer require noylecorp/laravel-recaptcha
包简介
Laravel package for Google's ReCAPTCHA service
关键字:
README 文档
README
Laravel Recaptcha
Laravel 5.1 package for Google reCAPTCHA, providing helper functions for creating reCAPTCHA fields and a service for validating responses.
Note: This package uses reCAPTCHA API version 2.0
Installation
Install Laravel Recaptcha with composer:
composer require noylecorp/laravel-recaptcha
Next, add the service provider to your config/app.php:
'providers' => [
// ...
Noylecorp\Recaptcha\RecaptchaServiceProvider::class,
]
Next, publish the package configuration file to your application:
php artisan vendor:publish --provider="Noylecorp\Recaptcha\RecaptchaServiceProvider"
The file recaptcha.php gets copied into your configuration directory. The final installation step is to add your reCAPTCHA site and secret keys to your .env file:
RECAPTCHA_SITE_KEY=your-site-key
RECAPTCHA_SECRET_KEY=your-secret-key
If you don't have reCAPTCHA keys you can signs up for a pair here.
Usage
Creating a reCAPTCHA widget
Easily create reCAPTCHA widgets using the recaptcha() helper function:
{!! recaptcha() !!}
// outputs...
<script src="https://www.google.com/recaptcha/api.js"></script>
<div class="g-recaptcha" data-sitekey="my-site-key"></div>
You can also pass in HTML attributes...
{!! recaptcha(['id' => 'myrecaptcha']) !!}
...or any of reCAPTCHA's available options:
{!! recaptcha(['theme' => 'dark']) !!}
{!! recaptcha(['data-theme' => 'dark']) !!} // same thing
If you need to render the <script> and <div> tags for the reCAPTCHA widget separately, you can use the recaptch_script() and recaptcha_widget() functions:
{!! recaptcha_script() !!}
// ...
{!! recaptcha_widget() !!}
Need to support users without JavaScript? You can also insert a <noscript> fallback:
{!! recaptcha() !!}
{!! recaptcha_noscript() !!}
Or, if you don't want to use any of those helper functions, you can use recaptcha_site_key() to grab the site key for your own custom markup:
<div class="g-recaptcha" data-sitekey="{{ recaptcha_site_key() }}"></div>
Finally, if you have LaravelCollective Html installed, all helper functions can also be accessed through the Form facade:
{!! Form::recaptcha() !!}
Validating reCAPTCHA responses
The simplest way to validate a reCAPTCHA field is by using the added recaptcha validation rule:
// in a controller...
$this->validate($request, [
'g-recaptcha-response' => 'required|recaptcha'
]);
// in a form request...
public function rules()
{
return [
'g-recaptcha-response' => 'required|recaptcha'
];
}
Or, you can access the service directly to do manual validation:
if (app('recaptcha')->verify($request->input('g-recaptcha-response'))) {
// user passed reCAPTCHA
}
else {
// user failed reCAPTCHA
}
noylecorp/laravel-recaptcha 适用场景与选型建议
noylecorp/laravel-recaptcha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.11k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「recaptcha」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 noylecorp/laravel-recaptcha 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 noylecorp/laravel-recaptcha 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 noylecorp/laravel-recaptcha 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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
CakePHP Captcha Plugin, Image, Math and Google Recaptcha Support
ReCaptcha form field integration for Symfony
DravenCMS Recaptcha
统计信息
- 总下载量: 11.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-16