PHP code example of stil / cool-captcha

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

    

stil / cool-captcha example snippets



ion_start();
use CoolCaptcha\Captcha;
$captcha = new Captcha();

/** OPTIONAL configuration
$captcha->wordsFile = 'words/es.php';
$captcha->session_var = 'secretword';
$captcha->imageFormat = 'png';
$captcha->lineWidth = 3;
$captcha->scale = 3;
$captcha->blur = true;
$captcha->resourcesPath = "/var/cool-php-captcha/resources";
**/

/** OPTIONAL Simple autodetect language example
if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
    $langs = array('en', 'es');
    $lang  = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    if (in_array($lang, $langs)) {
        $captcha->wordsFile = "words/$lang.php";
    }
}
**/

// Image generation
$text = $captcha->createImage();
$_SESSION['text'] = $text;