davchezt / captcha

A simple PHP CAPTCHA library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mobicms/captcha

This package is part of mobiCMS and JohnCMS, but can be used freely in any other projects.

GitHub GitHub release (latest SemVer) Packagist

CI-Analysis CI-Tests Code Coverage Scrutinizer Code Quality

YAGNI KISS

This library is a simple PHP CAPTCHA. Prevent form spam by generating random Captcha images.

Captchas examples

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

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.

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you are expected to uphold this code.

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

The mobicms/captcha library is licensed for use under the MIT License (MIT).
Please see LICENSE for more information.

Our links

About

A simple PHP CAPTCHA library

License:MIT License


Languages

Language:PHP 100.0%