PHPackages                             emotionloop/visualcaptcha - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. emotionloop/visualcaptcha

ActiveLibrary[Security](/categories/security)

emotionloop/visualcaptcha
=========================

PHP library for visualCaptcha. Still requires you to have the front-end companion.

0.0.8(9y ago)9126.9k↑59.1%7[1 PRs](https://github.com/desirepath41/visualCaptcha-packagist/pulls)1MITPHPPHP &gt;=5.3

Since Jan 31Pushed 9y ago4 watchersCompare

[ Source](https://github.com/desirepath41/visualCaptcha-packagist)[ Packagist](https://packagist.org/packages/emotionloop/visualcaptcha)[ Docs](http://visualcaptcha.net)[ RSS](/packages/emotionloop-visualcaptcha/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (2)Versions (7)Used By (1)

[![Build Status](https://camo.githubusercontent.com/128dd739dc8f1359af56af1593d730b64e1e50cbb718936b27bb36568dab0ecd/68747470733a2f2f7472617669732d63692e6f72672f656d6f74696f6e4c6f6f702f76697375616c436170746368612d7061636b61676973742e7376673f666c61743d74727565266272616e63683d6d6173746572)](https://travis-ci.org/emotionLoop/visualCaptcha-packagist)[![Codacy](https://camo.githubusercontent.com/f4fb405b8a7c0b6a74b7931a63d4183e686dbbb586da6e006ca511a4683b38b7/68747470733a2f2f7777772e636f646163792e636f6d2f70726f6a6563742f62616467652f3863633635646438316339303430613261396564323632623037643466613530)](https://www.codacy.com/app/bruno-bernardino/visualCaptcha-packagist)[![Code Climate](https://camo.githubusercontent.com/b0e90b5d19c25e09ba90667bcd7854b3b28edd1a19689e0f9c05c3759da22dcf/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f656d6f74696f6e4c6f6f702f76697375616c436170746368612d7061636b61676973742f6261646765732f6770612e737667)](https://codeclimate.com/github/emotionLoop/visualCaptcha-packagist)

visualCaptcha-packagist
=======================

[](#visualcaptcha-packagist)

Packagist composer package for visualCaptcha's backend service

Installation with Composer
--------------------------

[](#installation-with-composer)

You need PHP installed with [composer](https://getcomposer.org).

```
composer install emotionloop/visualcaptcha

```

Run tests
---------

[](#run-tests)

You need [PHPUnit](https://phpunit.de) installed and then you can run

```
composer install && phpunit tests

```

Usage
-----

[](#usage)

### Initialization

[](#initialization)

You have to initialize a session for visualCaptcha to inject the data it needs. You'll need this variable to start and verify visualCaptcha as well.

```
session_start();// Only needed once, at the beginning of your PHP files.
$session = new \visualCaptcha\Session( $namespace );

```

Where:

- `$namespace` is optional. It's a string and defaults to 'visualcaptcha'. You'll need to specifically set this if you're using more than one visualCaptcha instance in the same page, so the code can identify from which one is the validation coming from.

### Using Cache

[](#using-cache)

You can use a backend Zend-Cache library options to store images on cache and avoid I/O. You'll have to pass options parameter on the constructor as document in . By default it is disabled and you´ll have to pass true on the constructor on the 5th parameter.

```
$options = array(
                'adapter' => array(
                    'name'    => 'memory',
                    'options' => array('ttl' => 3600,
                        'namespace' => "captcha-service"),
                ),
                'plugins' => array(
                    'exception_handler' => array('throw_exceptions' => false),
                ),
            );

$captchaWithCache = new \visualCaptcha\Captcha( $this->session,null,null,null, true,$options);

```

### Setting Routes for the front-end

[](#setting-routes-for-the-front-end)

You also need to set routes for `/start/:howmany`, `/image/:index`, and `/audio/:index`. These will usually look like:

```
// Populates captcha data into session object
// -----------------------------------------------------------------------------
// @param howmany is required, the number of images to generate
$app->get( '/start/:howmany', function( $howMany ) use( $app ) {
    $captcha = new \visualCaptcha\Captcha( $app->session );
    $captcha->generate( $howMany );
    $app->response[ 'Content-Type' ] = 'application/json';
    echo json_encode( $captcha->getFrontEndData() );
} );

// Streams captcha images from disk
// -----------------------------------------------------------------------------
// @param index is required, the index of the image you wish to get
$app->get( '/image/:index', function( $index ) use( $app ) {
    $captcha = new \visualCaptcha\Captcha( $app->session );
    if ( ! $captcha->streamImage(
            $app->response,
            $index,
            $app->request->params( 'retina' )
    ) ) {
        $app->pass();
    }
} );

// Streams captcha audio from disk
// -----------------------------------------------------------------------------
// @param type is optional and defaults to 'mp3', but can also be 'ogg'
$app->get( '/audio(/:type)', function( $type = 'mp3' ) use( $app ) {
    $captcha = new \visualCaptcha\Captcha( $app->session );
    if ( ! $captcha->streamAudio( $app->response, $type ) ) {
        $app->pass();
    }
} );

```

### Validating the image/audio

[](#validating-the-imageaudio)

Here's how it'll usually look:

```
$session = new \visualCaptcha\Session();
$captcha = new \visualCaptcha\Captcha( $session );
$frontendData = $captcha->getFrontendData();

// If an image field name was submitted, try to validate it
if ( $imageAnswer = $app->request->params( $frontendData[ 'imageFieldName' ] ) ) {
  if ( $captcha->validateImage( $imageAnswer ) ) {
    // Image was valid.
  } else {
    // Image was submitted, but wrong.
  }
// Otherwise an audio field was submitted, so try to validate it
} else if ( $audioAnswer = $app->request->params( $frontendData[ 'audioFieldName' ] ) ) {
  if ( $captcha->validateAudio( $audioAnswer ) ) {
    // Audio answer was valid.
  } else {
    // Audio was submitted, but wrong.
  }
} else {
  // Apparently no fields were submitted, so the captcha wasn't filled.
}

```

### visualCaptcha/Session properties

[](#visualcaptchasession-properties)

- `$namespace`, String â€” This is private and will hold the namespace for each visualCaptcha instance. Defaults to 'visualcaptcha'.

### visualCaptcha/Session methods

[](#visualcaptchasession-methods)

- `__construct( $namespace )` â€” Initialize the visualCaptcha session.
- `clear()` â€” Will clear the session for the current namespace.
- `get( $key )` â€” Will return a value for the session's `$key`.
- `set( $key, $value )` â€” Set the `$value` for the session's `$key`.

### visualCaptcha/Captcha properties

[](#visualcaptchacaptcha-properties)

- `$session`, Object that will have a reference for the session object. It will have .visualCaptcha.images, .visualCaptcha.audios, .visualCaptcha.validImageOption, and .visualCaptcha.validAudioOption.
- `$assetsPath`, Assets path. By default, it will be './assets'
- `$imageOptions`, All the image options. These can be easily overwritten or extended using addImageOptions( ), or replaceImageOptions( ). By default, they're populated using the ./images.json file
- `$audioOptions`, All the audio options. These can be easily overwritten or extended using addAudioOptions( ), or replaceAudioOptions( ). By default, they're populated using the ./audios.json file

### visualCaptcha/Captcha methods

[](#visualcaptchacaptcha-methods)

You'll find more documentation on the code itself, but here's the simple list for reference.

- `__construct( $session, $assetsPath = null, $defaultImages = null, $defaultAudios = null )` â€” Initialize the visualCaptcha object.
- `generate( $numberOfOptions = 5 )` â€” Will generate a new valid option, within a `$numberOfOptions`.
- `streamAudio( $headers, $fileType )` â€” Stream audio file.
- `streamImage( $headers, $index, $isRetina )` â€” Stream image file given an index in the session visualCaptcha images array.
- `getFrontendData()` â€” Get data to be used by the frontend.
- `getValidImageOption()` â€” Get the current validImageOption.
- `getValidAudioOption()` â€” Get the current validAudioOption.
- `validateImage( $sentOption )` â€” Validate the sent image value with the validImageOption.
- `validateAudio( $sentOption )` â€” Validate the sent audio value with the validAudioOption.
- `getImageOptions()` â€” Return generated image options.
- `getImageOptionAtIndex( $index )` â€” Return generated image option at index.
- `getAudioOption()` â€” Alias for getValidAudioOption.
- `getAllImageOptions()` â€” Return all the image options.
- `getAllAudioOptions()` â€” Return all the audio options.

License
-------

[](#license)

View the [LICENSE](LICENSE) file.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 73.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~226 days

Recently: every ~275 days

Total

6

Last Release

3404d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/50df1e6cc47b33877f7abcfaaf3ff818382ca7ada3c65afce9b6c53bc1cbdee8?d=identicon)[emotionLoop](/maintainers/emotionLoop)

![](https://www.gravatar.com/avatar/4547f53b462d2ae235ec55872c9249fa64282d75d63d6d02ccc9fcfe8fff91ef?d=identicon)[desirepath41](/maintainers/desirepath41)

---

Top Contributors

[![rogerioefonseca](https://avatars.githubusercontent.com/u/17765109?v=4)](https://github.com/rogerioefonseca "rogerioefonseca (11 commits)")[![ghiscoding](https://avatars.githubusercontent.com/u/643976?v=4)](https://github.com/ghiscoding "ghiscoding (2 commits)")[![BrunoBernardino](https://avatars.githubusercontent.com/u/1239616?v=4)](https://github.com/BrunoBernardino "BrunoBernardino (1 commits)")[![klas](https://avatars.githubusercontent.com/u/331352?v=4)](https://github.com/klas "klas (1 commits)")

---

Tags

securitycaptchavisualCaptcha

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/emotionloop-visualcaptcha/health.svg)

```
[![Health](https://phpackages.com/badges/emotionloop-visualcaptcha/health.svg)](https://phpackages.com/packages/emotionloop-visualcaptcha)
```

###  Alternatives

[gregwar/captcha-bundle

Captcha bundle

3684.9M33](/packages/gregwar-captcha-bundle)[s1syphos/php-simple-captcha

Simple captcha generator

2740.9k11](/packages/s1syphos-php-simple-captcha)[lorddashme/php-simple-captcha

A simple captcha package that fit to any type of web application built on php.

113.0k](/packages/lorddashme-php-simple-captcha)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
