fluxsoft / php-turnstile
API Implementation of CloudFlare turnstile for PHP
Installs: 1 170
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 0
Forks: 2
Open Issues: 0
Requires
- php: >=7.0
README
Description
API Implementation of Cloudflare turnstile for PHP
Installation
composer require fluxsoft/php-turnstile
Usage
Here's an example of usage:
// require vendor use FluxSoft\Turnstile\Turnstile; $turnstile = new Turnstile('secret key'); $verifyResponse = $turnstile->verify($_POST['cf-turnstile-response'], $_SERVER['REMOTE_ADDR']); if ($verifyResponse->success) { // successfully verified captcha resolving } else { if ($verifyResponse->hasErrors()) { foreach ($verifyResponse->errorCodes as $errorCode) { echo $errorCode . '\n'; } } else { // unknown reason of failure resolving of captcha } }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <form action="" method="POST"> <div class="cf-turnstile" data-sitekey="YOUR_PUBLIC_SITE_KEY"></div> <button type="submit">check</button> </form> <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script> </body> </html>
License
The MIT License (MIT). Please see License File for more information.