PHPackages                             toolslib/turnstile-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. toolslib/turnstile-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

toolslib/turnstile-php
======================

0.1.0(1y ago)13PHP

Since Jan 29Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ToolsLib/turnstile-php)[ Packagist](https://packagist.org/packages/toolslib/turnstile-php)[ RSS](/packages/toolslib-turnstile-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Turnstile PHP Validator
=======================

[](#turnstile-php-validator)

This package provides a simple way to validate Cloudflare Turnstile CAPTCHA tokens using PHP and Guzzle. It allows you to integrate Cloudflare's CAPTCHA verification into your server-side application.

Installation
------------

[](#installation)

To install this package, use Composer:

```
composer require toolslib/turnstile-php
```

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- Guzzle HTTP Client (automatically installed with Composer)

Configuration
-------------

[](#configuration)

To use the validator, you need to have a valid Cloudflare Turnstile secret key. You can obtain this key from the [Cloudflare Turnstile Dashboard](https://developers.cloudflare.com/turnstile/).

Usage
-----

[](#usage)

### 1. Set Up the Validator

[](#1-set-up-the-validator)

First, create an instance of the `Validator` class and pass your secret key:

```
use ToolsLib\TurnstilePhp\Validator;

// Your Cloudflare Turnstile secret key
$secretKey = 'your-secret-key';

// Initialize the validator
$validator = new Validator($secretKey);
```

### 2. Validate the Turnstile Token

[](#2-validate-the-turnstile-token)

Next, you can use the `validateTurnstileToken` method to validate a CAPTCHA response from the user. This method requires the Turnstile token that was received from the client-side as well as an optional IP address (`CF-Connecting-IP` header from Cloudflare):

```
// Get the Turnstile response token from the form submission
$token = $_POST['cf-turnstile-response'];

// Get the user's IP address (optional, but recommended for extra validation)
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'] ?? null;

// Validate the token
$isValid = $validator->validateTurnstileToken($token, $ip);

// Check the result
if ($isValid) {
    // The CAPTCHA token is valid, proceed with your logic
    echo "CAPTCHA validation succeeded.";
} else {
    // The CAPTCHA token is invalid, handle the failure
    echo "CAPTCHA validation failed.";
}
```

### 3. Handle Errors

[](#3-handle-errors)

In case of an error (e.g., network issues, invalid response from Cloudflare), the method will return `false`. You can handle this by either logging the error or showing an appropriate message to the user.

```
try {
    // Validate the token
    $isValid = $validator->validateTurnstileToken($token, $ip);

    if ($isValid) {
        // CAPTCHA validation succeeded, proceed with your logic
        echo "CAPTCHA validation succeeded.";
    }
} catch (ToolsLib\TurnstilePhp\TurnstileValidationException $e) {
    // Handle the exception if validation fails
    echo "Error: " . $e->getMessage();
}
```

License
-------

[](#license)

This package is open-source and available under the GNU GPL v3 license.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to fork the repository, create a new branch, and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance42

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

474d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/334243c5ed57b57cc3715aef7319880e7dd91453f629d0fa48988a9148d8b54e?d=identicon)[cocochepeau](/maintainers/cocochepeau)

---

Top Contributors

[![sykz42](https://avatars.githubusercontent.com/u/113334184?v=4)](https://github.com/sykz42 "sykz42 (2 commits)")[![cocochepeau](https://avatars.githubusercontent.com/u/2019778?v=4)](https://github.com/cocochepeau "cocochepeau (1 commits)")

---

Tags

cloudflarephpturnstile

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/toolslib-turnstile-php/health.svg)

```
[![Health](https://phpackages.com/badges/toolslib-turnstile-php/health.svg)](https://phpackages.com/packages/toolslib-turnstile-php)
```

###  Alternatives

[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[dhlparcel/magento2-plugin

DHL Parcel plugin for Magento 2

11180.5k2](/packages/dhlparcel-magento2-plugin)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
