PHP code example of teampanfu / laravel-turnstile

1. Go to this page and download the library: Download teampanfu/laravel-turnstile library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

teampanfu / laravel-turnstile example snippets


$request->validate([
    'cf-turnstile-response' => ['turnstile'],
]);

'custom' => [
    'cf-turnstile-response' => [
        'turnstile' => 'Please verify that you are human.',
    ],
],



use Panfu\Laravel\Turnstile\Turnstile;

$turnstile = new Turnstile('your-secret-key');

try {
    if ($turnstile->validate($_POST['cf-turnstile-response'])) {
        // Verification successful
    }
} catch (\RuntimeException $e) {
    // Handle validation error (e.g., invalid-input-response)
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // Handle network/request error
}