A library implemented by PHP to generate captcha easily.
- PHP 5 +
- PHP GD
- composer
Please assure that you have installed php-gd, and install it via
apt install php7.0-gdorapt install php5-gdis recommended.
Here are two ways to install:
Using composer:
composer require php-quickorm/captchaor download the
Captcha.phpandarial.ttfto your project and import it byrequire "Captcha.php";
The captcha has three levels, and the first is the easiest.
image.php
$captcha = newCaptcha();
$_SESSION['code'] = $captcha->getCode();
$captcha->render();index.html
<imgsrc="image.php">// The Captcha has three levels, and the first is the easiest.$level = 3; // Case Sensitive$caseSensitive = false;
$captcha = newCaptcha($level, $caseSensitive);
// Get the code$code = $captcha->getCode();
// Get the php-gd image resource$im = $captcha->getImageResource();
// Check the code if correct$captcha->check("AbcD");
// Send HTTP response as a image$captcha->render();Here is a demo: https://github.com/php-quickorm/Captcha/tree/master/demo