PHP code example of vlinde / recaptcha
1. Go to this page and download the library: Download vlinde/recaptcha library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vlinde / recaptcha example snippets
return [
'secret_key' => env('RECAPTCHA_SECRET_KEY'),
'site_key' => env('RECAPTCHA_SITE_KEY'),
'is_active' => true,
'score' => 0.5,
'options' => [
'timeout' => 5.0,
]
];
{!! Recaptcha::renderJs() !!}
{!! Recaptcha::field('login') !!}
$validate = Validator::make(Input::all(), [
'g-recaptcha-response' => '
'custom' => [
'g-recaptcha-response' => [
'ontact site admin.',
],
],
@if ($errors->has('g-recaptcha-response'))
<p>{{ $errors->first('g-recaptcha-response') }}</p>
@endif
$token = $request->get('g-recaptcha-response');
$action = 'home';
$score = 0;
$score = app('recaptcha')->verify($token, $action, $score);
if($score > 0.7) {
// is valid
}
else if($score > 0.3) {
//
<html>
<head>
<title>Recaptcha v3</title>
{!! Recaptcha::renderJs('fa') !!}
</head>
<body>
<form action="{{ url('recaptcha-page') }}" method="post">
{!! csrf_field() !!}
{!! Recaptcha::field('home', 'g-recaptcha-response', ['id' => 'recaptcha-id', 'class' => 'form-element'], 'recaptchaCallback') !!}
<button type="submit">Submit</button>
</form>
@if($errors->any())
@foreach($errors->all() as $key => $error)
<p>{{ $key }} - {{ $error }}</p>
@endforeach
@endif
<script>
function recaptchaCallback(token) {
console.log('token retrieved:');
console.log(token);
}
</script>
</body>
</html>
class DevController extends Controller
{
public function verifyRecaptcha(Request $request)
{
$this->validate($request, ['g-recaptcha-response' => '
shell
php artisan vendor:publish --provider="Mostafaznv\Recaptcha\RecaptchaServiceProvider"
shell
php artisan vendor:publish --provider="Mostafaznv\Recaptcha\RecaptchaServiceProvider"