用于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 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!
