Skip to content

varg61/mobicms-captcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple PHP CAPTCHA library

License Latest Stable Version Latest Unstable Version Total Downloads

Build Status Scrutinizer Code Quality Code Climate SensioLabsInsight

This library is part of mobiCMS Content Management System, but can be used as an independent library in other projects. Prevent form spam by generating random Captcha images.

Captchas examples

Install via Composer

composer require mobicms/mobicms-captcha

Usage

  1. Generating code:

    $captcha = new Mobicms\Captcha\Captcha;
    $code = $captcha->generateCode();
    $_SESSION['code'] = $code;
  2. Display in form:

    <form method="post">
    <!-- ... -->
    <img alt="Verification code"
        width="<?= $captcha->width ?>"
        height="<?= $captcha->height ?>"
        src="<?= $captcha->generateImage($code) ?>"
    >
    <input type="text" size="5" name="code">
    <!-- ... -->
    </form>
  3. 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
        }
    }

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages