PHP code example of aminarjmand / pure-captcha
1. Go to this page and download the library: Download aminarjmand/pure-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/ */
aminarjmand / pure-captcha example snippets
minArjmand\PureCaptcha\Captcha;
Captcha::renderImage();
minArjmand\PureCaptcha\Captcha;
minArjmand\PureCaptcha\Captcha;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$captchaInput = $_POST['captcha'] ?? '';
if (Captcha::validate($captchaInput)) {
echo '✅ CAPTCHA is valid!';
// Process your form...
} else {
echo '❌ Invalid CAPTCHA. Please try again.';
}
}
return [
'lang' => 'en',
'font' => 'Vazirmatn.ttf',
'expiry' => 300,
'length' => 5,
'width' => 170,
'height' => 55,
'font_size' => 22,
'char_type' => 'mixed',
'case_sensitive' => false,
'noise_level' => 'medium',
];
Captcha::configure([
'noise_level' => 'extreme',
'length' => 6,
'lang' => 'en',
'char_type' => 'letters',
]);
Captcha::configure(['length' => 6, 'noise_level' => 'high']);
$lang = Captcha::get('lang'); // 'fa'
$code = Captcha::generate();
if (Captcha::validate($_POST['captcha'])) {
// Valid!
}
Captcha::renderImage();
echo Captcha::html('captcha_image.php', 'captcha', 'en');
echo Captcha::styles();
// Filename only (looks in package's fonts/ directory)
'font' => 'MyCustomFont.ttf'
// Or full path
'font' => '/path/to/fonts/MyCustomFont.ttf'
Captcha::configure([
'char_type' => 'numbers',
'length' => 4,
'noise_level' => 'low',
]);
Captcha::configure([
'char_type' => 'mixed',
'length' => 7,
'noise_level' => 'extreme',
'case_sensitive' => true,
'expiry' => 120,
]);
Captcha::configure(['lang' => 'en']);
// Or override in html() only
echo Captcha::html('captcha_image.php', 'captcha', 'en');
minArjmand\PureCaptcha\Captcha;
Captcha::renderImage();
minArjmand\PureCaptcha\Captcha;
minArjmand\PureCaptcha\Captcha;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$captchaInput = $_POST['captcha'] ?? '';
if (Captcha::validate($captchaInput)) {
echo '✅ کد امنیتی صحیح است!';
// پردازش فرم...
} else {
echo '❌ کد امنیتی اشتباه است. لطفاً دوباره تلاش کنید.';
}
}
return [
'lang' => 'fa',
'font' => 'Vazirmatn.ttf',
'expiry' => 300,
'length' => 5,
'width' => 170,
'height' => 55,
'font_size' => 22,
'char_type' => 'mixed',
'case_sensitive' => false,
'noise_level' => 'medium',
];
Captcha::configure([
'noise_level' => 'extreme',
'length' => 6,
'lang' => 'fa',
'char_type' => 'letters',
]);
Captcha::configure(['length' => 6, 'noise_level' => 'high']);
$lang = Captcha::get('lang'); // 'fa'
$code = Captcha::generate();
if (Captcha::validate($_POST['captcha'])) {
// معتبر است!
}
Captcha::renderImage();
echo Captcha::html('captcha_image.php', 'captcha', 'fa');
echo Captcha::styles();
// فقط نام فایل (در پوشه fonts/ پکیج جستجو میشود)
'font' => 'MyCustomFont.ttf'
// یا مسیر کامل
'font' => '/path/to/fonts/MyCustomFont.ttf'
Captcha::configure([
'char_type' => 'numbers',
'length' => 4,
'noise_level' => 'low',
]);
Captcha::configure([
'char_type' => 'mixed',
'length' => 7,
'noise_level' => 'extreme',
'case_sensitive' => true,
'expiry' => 120,
]);
Captcha::configure(['lang' => 'en']);
// یا فقط در html() تغییر زبان
echo Captcha::html('captcha_image.php', 'captcha', 'en');