mobicms / captcha
A simple PHP CAPTCHA library
Installs: 7 525
Dependents: 1
Suggesters: 0
Security: 0
Stars: 23
Watchers: 4
Forks: 2
Open Issues: 0
Requires
- php: ~8.0 || ~8.1 || ~8.2
- ext-gd: *
Requires (Dev)
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^8.6
- squizlabs/php_codesniffer: ^3.7
- vimeo/psalm: ^5.1
README
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:
Installation
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
Usage
- 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 } }
Contributing
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.
License
This package is licensed for use under the MIT License (MIT).
Please see LICENSE for more information.
Our links
- mobiCMS Project website and support forum
- GitHub mobiCMS project repositories