用于Laravel框架的 No CAPTCHA reCAPTCHA 实现
Installation
Add the following line to the require section of composer.json:
{ "require": { "anhskohbo/no-captcha": "*" } } Run composer update.
Laravel
Setup
Add ServiceProvider to the providers array in app/config/app.php.
'Anhskohbo\NoCaptcha\NoCaptchaServiceProvider', Configuration
Run php artisan config:publish anhskohbo/no-captcha (publish:config if you use Laravel 5).
Fill secret and sitekey config in app/config/packages/anhskohbo/no-captcha/config.php file:
<?php return array( 'secret' => '', 'sitekey' => '', );
Usage
Display reCAPTCHA
Insert reCAPTCHA inside your form using one of this examples:
For Laravel 4
<?php echo Form::captcha() ?>For Laravel 4 using Blade syntax
{{ Form::captcha() }}For Laravel 5
<?php echo app('captcha')->display(); ?>For Laravel 5 using Blade syntax
{!! app('captcha')->display(); !!}For Laravel 5 with illuminate/html package using Blade syntax
{!! Form::captcha() !!}Validation
Add 'g-recaptcha-response' => 'required|captcha' to rules array.
$validate = Validator::make(Input::all(), [ 'g-recaptcha-response' => 'required|captcha' ]);
Without Laravel
Checkout example below:
<?php require_once "vendor/autoload.php"; $secret = ''; $sitekey = ''; $captcha = new \Anhskohbo\NoCaptcha\NoCaptcha($secret, $sitekey); if ( ! empty($_POST)) { var_dump($captcha->verifyResponse($_POST['g-recaptcha-response'])); exit(); } ?> <form action="?" method="POST"> <?php echo $captcha->display(); ?> <button type="submit">Submit</submit> </form> 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
