Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/davodm/codeigniter4-turnstile

CodeIgniter 4 package for integrating Cloudflare Turnstile Captcha
https://github.com/davodm/codeigniter4-turnstile

captcha cloudflare codeigniter4 php turnstile

Last synced: about 1 month ago
JSON representation

CodeIgniter 4 package for integrating Cloudflare Turnstile Captcha

Awesome Lists containing this project

README

        

# Cloudflare Turnstile for CodeIgniter 4
![Build Status](https://github.com/davodm/codeigniter4-turnstile/actions/workflows/main.yml/badge.svg)
![Packagist Version](https://img.shields.io/packagist/v/davodm/codeigniter4-turnstile)
![License](https://img.shields.io/github/license/davodm/codeigniter4-turnstile)
![Downloads](https://img.shields.io/packagist/dt/davodm/codeigniter4-turnstile)
![GitHub stars](https://img.shields.io/github/stars/davodm/codeigniter4-turnstile?style=social)

**CI4CFTurnstile** is a [CodeIgniter 4](https://github.com/codeigniter4/CodeIgniter4) library that integrates Cloudflare's Turnstile CAPTCHA for form validation. It supports both implicit and explicit rendering modes.

You can find the document of Cloudflare Turnstile [here](https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/).

## Installation
### 1. Composer Installation
Install the package via [Composer](https://getcomposer.org/):

```bash
composer require davodm/codeigniter4-turnstile
```
### 2. Configuration
After installation, configure your Cloudflare Turnstile site and secret keys. You can do this by setting the environment variables in your .env file:

```bash
turnstile.siteKey=your-site-key
turnstile.secretKey=your-secret-key
```

## Usage

### Rendering CAPTCHA

The library provides helper functions `turnsitle` to render the CAPTCHA in your views: `turnstile_implicit()`, `turnstile_explicit()`, and `turnstile_explicit_render()`.

#### Implicit Mode
In your view file, you can render the Turnstile CAPTCHA in implicit mode by calling:

```php
helper('turnstile');
echo turnstile_implicit('turnstile_field_name', 'auto', 'normal');
```

#### Explicit Mode

For explicit mode, you need to follow these steps:

1. **Register Fields**: In your view file, register the fields where the CAPTCHA should appear:

```php
helper('turnstile');
turnstile_explicit('turnstile_field_name', 'dark', 'normal');
```

2. **Create a

Element**: Manually create a
element in your view with an id matching the fieldName parameter:

```php


```

3. **Render the CAPTCHA**: Finally, render the CAPTCHA by calling turnstile_explicit_render() before the closing