This library is a simple PHP CAPTCHA. Prevent form spam by generating random Captcha images.
Major features:
- lightweight and fast
- not create any temporary files
- there are many settings that allow you to change the look of the picture
- you can use your own font sets
Example:
The preferred method of installation is via Composer. Run the following
command to install the package and add it as a requirement to your project's
composer.json
:
composer require mobicms/captcha
- Display in form:
<?php
$code = (string) new Mobicms\Captcha\Code;
$_SESSION['code'] = $code;
?>
<form method="post">
<!-- ... -->
<img alt="Verification code" src="<?= new Mobicms\Captcha\Image($code) ?>">
<input type="text" size="5" name="code">
<!-- ... -->
</form>
- Check whether the entered code is correct:
$result = filter_input(INPUT_POST, 'code');
$session = filter_input(INPUT_SESSION, 'code');
if ($result !== null && $session !== null) {
if (strtolower($result) == strtolower($session)) {
// CAPTCHA code is correct
} else {
// CAPTCHA code is incorrect, show an error to the user
}
}
Contributions are welcome! Please read Contributing for details.
In our development, we follow the principles of YAGNI and KISS. The source code should not have extra unnecessary functionality and should be as simple and efficient as possible.
This package is licensed for use under the MIT License (MIT).
Please see LICENSE for more information.
- mobiCMS Project website and support forum
- GitHub mobiCMS project repositories