PHP code example of gkcaptcha / gkcaptcha-laravel
1. Go to this page and download the library: Download gkcaptcha/gkcaptcha-laravel 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/ */
gkcaptcha / gkcaptcha-laravel example snippets
use GkCaptcha\Laravel\Http\Middleware\VerifyCaptcha;
Route::middleware([VerifyCaptcha::class])->group(function () {
Route::post('/contact', [ContactController::class, 'store']);
Route::post('/register', [RegisterController::class, 'store']);
});
protected $routeMiddleware = [
// ...
'captcha' => \GkCaptcha\Laravel\Http\Middleware\VerifyCaptcha::class,
];
Route::post('/contact', [ContactController::class, 'store'])->middleware('captcha');
// In a FormRequest class:
public function rules(): array
{
return [
'email' => '
use GkCaptcha\Laravel\Rules\GkCaptchaRule;
use GkCaptcha\GkCaptchaClient;
$rules = [
'captchaToken' => ['
use GkCaptcha\Laravel\Facades\GkCaptcha;
$result = GkCaptcha::verifyToken(
token: $request->input('captchaToken'),
clientIP: $request->ip(),
userAgent: $request->userAgent(),
);
if (!$result->success) {
abort(403, 'CAPTCHA verification failed');
}
bash
php artisan vendor:publish --tag=gkcaptcha-config
bash
php tests/run_tests.php