PHP code example of switon / captcha

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

    

switon / captcha example snippets


use Switon\Captcha\CaptchaInterface;
use Switon\Captcha\CaptchaProof;
use Switon\Core\Attribute\Autowired;

class LoginController
{
    #[Autowired] protected CaptchaInterface $captcha;

    public function getCaptcha(): array
    {
        return $this->captcha->create();
    }

    public function verify(string $key, string $code): void
    {
        $this->captcha->verify(CaptchaProof::of($key, $code));
    }
}