1. Go to this page and download the library: Download onnov/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/ */
onnov / captcha example snippets
/** @var Captcha */
protected $captcha;
public function __construct(Captcha $captcha) {
$this->captcha = $captcha;
}
use Onnov\Captcha\Captcha;
$captcha = new Captcha();
/**
* Returns CaptchaReturn Object
*
* @var CaptchaReturn $result
*/
$result = $captcha->getCaptcha();
// Save the value of the captcha in the session
$_SESSION['CaptchaKeyString'] = $result->getKeyString();
// Send the desired headers
foreach ($result->getHeaders() as $k => $v) {
header($k.': '.$v);
}
// Send captcha to browser
echo $result->getImg();
use Onnov\Captcha\Font\MonsterShadowFont;
use Onnov\Captcha\CaptchaConfig;
$captchaConfig = (new CaptchaConfig())->setFonts([new MonsterShadowFont()]);
$result = $captcha
->setConfig($captchaConfig)
->getCaptcha();
use Onnov\Captcha\Font\ActionJacksonFont;
use Onnov\Captcha\Font\MonsterShadowFont;
use Onnov\Captcha\Font\Baveuse3dFont;
use Onnov\Captcha\CaptchaConfig;
$captchaConfig = (new CaptchaConfig())
->setFonts(
[
new ActionJacksonFont(),
new MonsterShadowFont(),
new Baveuse3dFont(),
]
);
$result = $captcha
->setConfig($captchaConfig)
->getCaptcha();
use Onnov\Captcha\Font\ModelFont;
use Onnov\Captcha\CaptchaConfig;
$font = (new ModelFont())
->setFontPath(__DIR__.'/SignboardCpsNr.ttf')
->setCharWidth(25)
->setCharHeight(30);
$captchaConfig = (new CaptchaConfig())->setFonts([$font]);
$result = $captcha
->setConfig($captchaConfig)
->getCaptcha();
use Onnov\Captcha\CaptchaConfig;
$captchaConfig = (new CaptchaConfig())->setEffects([]);
$result = $captcha
->setConfig($captchaConfig)
->getCaptcha();
use Onnov\Captcha\CaptchaConfig;
use Onnov\Captcha\Effect\WaveDistortionEffect;
$captchaConfig = (new CaptchaConfig())->setEffects([new WaveDistortionEffect()]);
$result = $captcha
->setConfig($captchaConfig)
->getCaptcha();
use Onnov\Captcha\CaptchaConfig;
use Onnov\Captcha\Effect\WaveDistortionEffect;
use Onnov\Captcha\Effect\InterferenceEffect;
$captchaConfig = (new CaptchaConfig())
->setEffects(
[
new WaveDistortionEffect(),
new InterferenceEffect(),
]
);
$result = $captcha
->setConfig($captchaConfig)
->getCaptcha();
use Onnov\Captcha\CaptchaConfig;
use Onnov\Captcha\Effect\InterferenceConfig;
use Onnov\Captcha\Effect\InterferenceEffect;
use Onnov\Captcha\Effect\WaveDistortionConfig;
use Onnov\Captcha\Effect\WaveDistortionEffect;
$waveDistortionConfig = (new WaveDistortionConfig())
->setAmplitudeStart(300)
->setAmplitudeEnd(500)
->setAmplitudeDivider(120);
$interferenceConfig = (new InterferenceConfig())
->setInterferenceMin(25)
->setInterferenceMax(35)
->setInterferenceSymbols(':#~');
$captchaConfig = (new CaptchaConfig())
->setEffects(
[
new WaveDistortionEffect($waveDistortionConfig),
new InterferenceEffect($interferenceConfig),
]
);
$result = $captcha
->setConfig($captchaConfig)
->getCaptcha();
use Onnov\Captcha\CaptchaConfig;
$captchaConfig = (new CaptchaConfig())
->setWidth(120)
->setHeight(70)
->setPadding(5)
->setBackgroundColor([255,255,220])
->setForegroundColor([0,100,100]);
$result = $captcha
->setConfig($captchaConfig)
->getCaptcha();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.