PHP code example of zaymedia / captcha

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

    

zaymedia / captcha example snippets


Use ZayMedia\Captcha\Captcha;
use ZayMedia\Captcha\CacheAdapters\SimpleFileCacheAdapter;

$captcha = Captcha::make('1', new SimpleFileCacheAdapter(__DIR__ . '/cache'));

var_dump($captcha->generateLinks());

use ZayMedia\Captcha\CacheAdapters\AbstractCacheAdapter;

class MyCustomCacheAdapter extends AbstractCacheAdapter
{
    public function remember(string $key, int $expiresIn, callable $callback): mixed
    {
        //
    }

    public function get(string $key): mixed
    {
        //
    }

    public function forget(string $key): bool
    {
        //
    }
}

$links = $captcha->generateLinks(amount: 3);

$captcha->validateAnswer($answer);

$captcha->flushLinks();

// Enable or Disable image noise (Default: true)
$captcha->noise(value: false);

// Enable or Disable image background (Default: false)
$captcha->background(value: true);

// Enable or Disable dark theme (Default: false)
$captcha->darkTheme(value: true);

$wordUniverse = [...];

$captcha->wordUniverse($wordUniverse);
// Or...
$captcha->mergeWordUniverse($wordUniverse);