teampanfu/laravel-turnstile
最新稳定版本:v1.1.0
Composer 安装命令:
composer require teampanfu/laravel-turnstile
包简介
Laravel package for Cloudflare's Turnstile CAPTCHA service
README 文档
README
A Laravel package that integrates Cloudflare's Turnstile CAPTCHA service.
Requirements
For Laravel integration:
- PHP 8.2 or higher
- Laravel 9 or higher
For standalone usage:
- PHP 8.2 or higher
- Guzzle HTTP 7.8 or higher
Installation
composer require teampanfu/laravel-turnstile
Laravel Integration
- Add to your
.env:
TURNSTILE_SITEKEY=1x00000000000000000000AA
TURNSTILE_SECRET=1x0000000000000000000000000000000AA
Add the Widget
<form method="POST"> @csrf <div class="cf-turnstile" data-sitekey="{{ config('turnstile.sitekey') }}"></div> <button type="submit">Submit</button> </form> <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
See available configurations for theme, language, etc.
Validate the Response
$request->validate([ 'cf-turnstile-response' => ['required', 'turnstile'], ]);
Custom Error Message
In lang/[lang]/validation.php:
'custom' => [ 'cf-turnstile-response' => [ 'turnstile' => 'Please verify that you are human.', ], ],
Standalone Usage
The package can also be used without Laravel:
<?php use Panfu\Laravel\Turnstile\Turnstile; $turnstile = new Turnstile('your-secret-key'); try { if ($turnstile->validate($_POST['cf-turnstile-response'])) { // Verification successful } } catch (\RuntimeException $e) { // Handle validation error (e.g., invalid-input-response) } catch (\GuzzleHttp\Exception\GuzzleException $e) { // Handle network/request error }
Testing
./vendor/bin/phpunit
License
统计信息
- 总下载量: 302
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-17