derekcodes/turnstile-laravel
Composer 安装命令:
composer create-project derekcodes/turnstile-laravel
包简介
A Laravel package to facilitate the server side validation of Cloudflare's Turnstile captcha service.
README 文档
README
A Laravel package to facilitate the server side validation of Cloudflare's Turnstile captcha service.
Configuration
First you'll need an account Cloudflare and Turnstile setup for your website.
https://developers.cloudflare.com/turnstile/
Installation
Install via composer
composer require derekcodes/turnstile-laravel
Adding your secret key in the .env file
TURNSTILE_SITE_KEY="0x4AAAAAAAXXXXXXXXXXXXXX" TURNSTILE_SECRET_KEY="0x4AAAAAAAXXXXXXXXXXXXXX"
Create a config/turnstile.php
php artisan vendor:publish --tag=turnstile-config
Front-end
Be sure to add the front-end JavaScript from Turnstile: https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/
To save you some time, here's the Turnstile JavaScript necessary for an HTML form. Note that I assume you're using a Blade template, thus the {{ config('turnstile.site_key') }}.
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onloadTurnstileCallback" defer></script> window.onloadTurnstileCallback = function () { turnstile.render('#your-form-id', { sitekey: '{{ config('turnstile.site_key') }}', callback: function(token) { console.log(`Challenge Success ${token}`); }, }); };
Usage
Add the use statement at the top of your file
use DerekCodes\TurnstileLaravel\TurnstileLaravel;
Initiate the TursileLaravel object and call the validate method passing the client response Turnstile's JavaScript provides
$turnstile = new TurnstileLaravel; $response = $turnstile->validate($request->get('cf-turnstile-response'));
Ensure the response is valid
if (get_data($response, 'status', 0) == 1) { // TODO: add success code here }
Responses
Example success response
{
"status": 1
}
Example error response
{
"status": 0,
"turnstile_response": {
"success": false,
"error-codes": [
"invalid-input-response"
],
"messages": []
}
}
Credits
~ Derek Codes
- Website: https://www.derekcodes.io
- Twitter: https://twitter.com/DerekCodes_io
Derek Codes is a comprehensive collection of tutorials on the most popular languages in the industry. You’ll find videos, guides and downloadable assets to help you learn to code PHP, Laravel, JavaScript, CSS and more. Thanks for watching!
derekcodes/turnstile-laravel 适用场景与选型建议
derekcodes/turnstile-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 136.39k 次下载、GitHub Stars 达 57, 最近一次更新时间为 2022 年 12 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「cloudflare」 「turnstile」 「derekcodes」 「turnstile-laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 derekcodes/turnstile-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 derekcodes/turnstile-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 derekcodes/turnstile-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony bundle for Cloudflare integration: trusted proxies, real client IP detection, forwarded headers.
Multi-provider captcha integration for Filament forms (hCaptcha, reCAPTCHA v2/v3, Turnstile)
PHP package for easy integration with solvecaptcha API.
This plugin brings Google's reCAPTCHA, hCaptcha, and Cloudflare Turnstile integration to mautic.
Cloudflare Middleware For Guzzle
Library for helping bypass the Cloudflare IUAM page
统计信息
- 总下载量: 136.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 57
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-20