Last active
November 10, 2017 14:10
-
-
Save Crowles/7f18264d82c3efaf58f14494091ba442 to your computer and use it in GitHub Desktop.
Google's reCAPTCHA trait class - use with google/recaptcha package.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Reusable Captcha trait. | |
* | |
* to use this trait, simply include it inside your class via use statement. | |
* Then you just need to call $this->captchaCheck(); | |
*/ | |
namespace App\Http\Traits; | |
use Illuminate\Support\Facades\Input; | |
use ReCaptcha\ReCaptcha; | |
/** | |
* Trait CaptchaTrait | |
*/ | |
trait CaptchaTrait { | |
public function captchaCheck() | |
{ | |
$response = Input::get('g-recaptcha-response'); | |
$remoteip = $_SERVER['REMOTE_ADDR']; | |
$secret = env('RECAPTCHA_SECRET_KEY'); | |
$recaptcha = new ReCaptcha($secret); | |
$resp = $recaptcha->verify($response, $remoteip); | |
if ($resp->isSuccess()) { | |
return 1; | |
} else { | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment