fsorge/cloudflare-turnstile-php
最新稳定版本:1.0.0
Composer 安装命令:
composer require fsorge/cloudflare-turnstile-php
包简介
Validate Cloudflare Turnstile captchas with ease
README 文档
README
An unofficial PHP package to validate Cloudflare Turnstile captchas with ease. Read more at the Cloudflare official documentation.
Requirements
- PHP >= 8.1
Getting started
- Download this package with Composer
composer require fsorge/cloudflare-turnstile-php
- Create a new
Turnstileinstance
use Fsorge\Cloudflare\Turnstile; $turnstile = new Turnstile('YOUR_SECRET_KEY');
- Call the
isValid()method
$isCaptchaValid = $turnstile->isValid('RESPONSE_FROM_CLIENT');
- That's it!
Dictionary
- YOUR_SECRET_KEY: you can retrieve your secret key by going to your Cloudflare Turnstile dashboard, clicking "Settings" on your website, expanding the "Secret key" section and copying the key somewhere in your project and passing it to the
Turnstileconstructor - RESPONSE_FROM_CLIENT: it's a hidden field (with the
nameattribute set tocf-turnstile-response) that the Turnstile client-side widget automatically creates in your form. You have to pass that field's value.
Full simple example
use Fsorge\Cloudflare\Turnstile; $turnstile = new Turnstile('0x......'); $isCaptchaValid = $turnstile->isValid('0.id8uAhu.....'); if ($isCaptchaValid) { // Captcha has been validated } else { // Captcha NOT validate }
Detailed response
If you need to have the full response from the Cloudflare Turnstile API, you can call the validate() method instead of the isValid().
validate() returns an associative array with the whole response from the Cloudflare API, containing useful information like occurred errors if any.
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-10