PHP code example of trisnawan / captcha-gateway

1. Go to this page and download the library: Download trisnawan/captcha-gateway 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/ */

    

trisnawan / captcha-gateway example snippets


use Trisnawan\CaptchaGateway\Captcha;

$captcha = new Captcha("VENDOR", "PROJECT", "SITE_KEY", "SECRET_KEY");

$captcha = new Captcha();

// 1. load script
echo $captcha->client->script();

// 2. render
echo $captcha->client->render("ACTION", "INPUT_ID", "BUTTON_ID");

// 1. VERIFY - default
$validation = $captcha->server->verify("login-action");

// 1. VERIFY - manual token data
$token = $_POST['captcha-token'];
$validation = $captcha->server->verify("login-action", $token);

// 1. VERIFY - manual token data + IP verification
$ip = $_SERVER['HTTP_CLIENT_IP'] ?? $_SERVER['REMOTE_ADDR'] ?? null;
$token = $_POST['captcha-token'];
$validation = $captcha->server->verify("login-action", $token, $ip);

// 2. CHECK VALIDATION
if(!$validation->isSuccess){
    $messageError = $validation->errorMessage;
    $arrayErrors = $validation->errors;
    // show error
}