PHPackages                             elcodedocle/captchalot - 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. [API Development](/categories/api)
4. /
5. elcodedocle/captchalot

ActiveProject[API Development](/categories/api)

elcodedocle/captchalot
======================

Captcha image generator/validator RESTful web service

1.2.0(1y ago)25MITPHPPHP &gt;=5.3.0

Since Feb 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/elcodedocle/captchalot)[ Packagist](https://packagist.org/packages/elcodedocle/captchalot)[ Docs](https://github.com/elcodedocle/captchalot)[ RSS](/packages/elcodedocle-captchalot/feed)WikiDiscussions master Synced 1mo ago

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

Captchalot
==========

[](#captchalot)

##### *A dictionary/symbol based captcha generator and validator RESTful service*

[](#a-dictionarysymbol-based-captcha-generator-and-validator-restful-service)

Copyright (C) 2014 Gael Abadin
License: [MIT Expat](https://raw.githubusercontent.com/elcodedocle/captchalot/master/LICENSE)

[![captchalot captcha generator test site snapshot with default settings](https://camo.githubusercontent.com/95cea8ace9c4d586ed4f644f039a7dffd09c1605db0b26302f4485ebfc445187/687474703a2f2f692e696d6775722e636f6d2f556d316a4570702e706e67 "This is how captchalot's test web app looks like. Check it out on https://synapp.info/tools/captchalot ;-) )")](https://camo.githubusercontent.com/95cea8ace9c4d586ed4f644f039a7dffd09c1605db0b26302f4485ebfc445187/687474703a2f2f692e696d6775722e636f6d2f556d316a4570702e706e67)

### Motivation

[](#motivation)

I wanted to implement a simple, easy to use, scalable and independent RESTful captcha service on my web app.

### Requirements

[](#requirements)

- PHP &gt;= 5.3 with PDO support
- MySQL / MariaDB, Postgres; or a PDO supported DB

### Deployment

[](#deployment)

- You can install and deploy captchalot using composer:

```
php composer.phar create-project -s "beta" elcodedocle/captchalot
```

- You need to edit `config.php.dist` in order to provide basic database connection parameters; then save it as `config.php`.
- Here is a basic client written in javascript to AJAX request/refresh/validate a captcha:

```
var captchalot = {

    'validate' : function(opts){

        let XHR = new XMLHttpRequest(),
            responseJSON,
            parameters,
            options = (typeof (opts) === 'object')?opts:{
                uuid: '',
                magicword: '',
                width: 350,
                height: 50,
                callbackSuccess: function(responseJSON){ alert('success!'); console.log(responseJSON); },
                callbackError: function(responseJSON){ alert('error!'); console.log(responseJSON); }
            };

        XHR.addEventListener("load", function(event) {

            try {
                responseJSON = JSON.parse(event.target.responseText);
                if (
                    !('data' in responseJSON) ||
                    !('validationResult' in responseJSON.data) ||
                        responseJSON.data['validationResult'] !== 'ERROR'
                          && responseJSON.data['validationResult'] !== 'PENDING'
                            && responseJSON.data['validationResult'] !== 'OK'
                ){
                    console.log(
                        "Cannot understand response from server:\n"
                            + responseJSON
                    );
                    options.callbackError(responseJSON);
                } else {
                    if ( responseJSON.data['validationResult'] === 'OK' ){
                        options.callbackSuccess(responseJSON);
                    } else {
                        options.callbackError(responseJSON);
                    }
                }
            } catch (e) {
                console.error("Parsing error:", e);
                console.log(event.target.responseText);
            }

        });

        XHR.addEventListener("error", function(event) {
            alert('Something went wrong ¯\\(º_o)/¯');
            console.log(event.target.responseText);
        });

        XHR.open("POST", 'validate.php', true);
        XHR.setRequestHeader(
            'Content-type',
            'application/x-www-form-urlencoded'
        );
        parameters = 'uuid='
            + options.uuid
            + '&magicword='
            + encodeURIComponent(options.magicword)
            + '&width='+options.width
            + '&height='+options.height;
        XHR.send(parameters);

    }

};
```

- And here is the server-side PHP controller for this client:

```
