kamotelab/php-turnstile
最新稳定版本:v1.2.1
Composer 安装命令:
composer require kamotelab/php-turnstile
包简介
PHP implementation of cloudflare's turnstile
README 文档
README
A lightweight PHP implementation of Cloudflare's Turnstile
Requirements
- PHP ^8.3
- Any PSR-17, PSR-18 and HTTPlug implementations (ie Symfony HTTP Client)
Installation
composer require kamotelab/php-turnstile
Example Usage
<?php
use KamoteLab\Turnstile;
class YourClass
{
private Turnstile $turnstile
public function __construct(Turnstile $turnstile) {
$this->turnstile = new Turnstile('{Turnstile Secret Key}');
}
/*
* $response (required) = turnstile response from client side render on your site.
* $idempotencyKey (optional) = use this if you need to retry failed request.
* $remoteIp (optional) = The visitor’s IP address.
*/
public function yourMethod(string $response, ?string $idempotencyKey = null, ?string $remoteIp = null) {
try {
$this->turnstile->verify($response, $idempotencyKey, $remoteIp)
} catch (Exception $e) {
// next step in case of exception
}
}
}
Disclaimer
- This library will not throw any exception when the response code is 4xx or 5xx
- You will have to implement your own error handling when response code is 4xx, 5xx
- You will have to implement your own error handling when error was thrown
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-10