1. Go to this page and download the library: Download elcodedocle/captchalot 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/ */
elcodedocle / captchalot example snippets
nfo\synapp\tools\captcha\Session;
use info\synapp\tools\uuid\UUID;
use info\synapp\tools\captcha\CaptchaWord;
use info\synapp\tools\captcha\CaptchaImage;
use info\synapp\tools\captcha\Captcha;
session_start();
ob_start();
$VALIDATION_RESULT_PENDING = 'PENDING';
$VALIDATION_RESULT_OK = 'OK';
$VALIDATION_RESULT_ERROR = 'ERROR';
$session = new Session(session_id());
$session->removeExpiredCaptchas();
$uuidGenerator = new UUID();
$captchaWord = new CaptchaWord();
$options=array('options'=>array('default'=>420, 'min_range'=>70, 'max_range'=>4200));
$width=filter_input(INPUT_POST, 'width', FILTER_VALIDATE_INT, $options);
$options=array('options'=>array('default'=>60, 'min_range'=>10, 'max_range'=>600));
$height=filter_input(INPUT_POST, 'height', FILTER_VALIDATE_INT, $options);
$captchaImage = new CaptchaImage($width,$height);
$captcha = new Captcha($session,null,$uuidGenerator,$captchaWord,$captchaImage);
$output = array(
'data' => array(
'validationResult' => $VALIDATION_RESULT_PENDING,
),
);
if (
isset($_REQUEST['uuid'])
&& $_REQUEST['uuid']!==''
&& isset($_REQUEST['magicword'])
&& $_REQUEST['magicword']!==''
){
if($captcha->validate($_REQUEST['uuid'],$_REQUEST['magicword'])){
$output['data']['validationResult'] = $VALIDATION_RESULT_OK;
} else {
$output['data']['validationResult'] = $VALIDATION_RESULT_ERROR;
}
}
if($output['data']['validationResult']!==$VALIDATION_RESULT_OK){
$output['data']=array_merge(
$output['data'],
$captcha->getCaptchaUuidAndImgBase64SrcAttrVal()
);
}
header('Content-type: application/json');
header('Expires: Sun, 1 Jan 2000 12:00:00 GMT');
header('Last-Modified: '.gmdate("D, d M Y H:i:s").'GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
$jsonOutput = json_encode($output);
echo $jsonOutput;
ob_end_flush();