Home

Awesome

Build Status Codacy Code Climate

visualCaptcha-PHP

PHP sample for visualCaptcha.

This is a demo/sample PHP app that uses the visualCaptcha PHP composer/packagist package and the visualCaptcha jQuery plugin bower package, as a proof-of-concept for how to integrate it with your PHP project.

NOTES FOR BEGINNERS

If you're used to the simpler, older version of visualCaptcha, you can still get version 4.2.0, but note it's harder to update and it has a potential flaw that could make bots override it, though it isn't a big concern if you understand how it's done.

If you're not familiar with building APIs, custom routes, composer, or bower, you should also consider using that simpler version.

This won't look like the current demo, because all demos use version 5.0+.

Installation

You need PHP 5.3+ installed with composer. Use the following command if you've got composer locally installed:

php composer.phar install

If you've got composer installed globally, use the following command

composer install

This will install the visualCaptcha package, PHPUnit, and Slim (for the API demo).

Run server

If you don't have a server running, you can use PHP's new built-in server to run it, for example on port 8282, by typing the following command:

php -S localhost:8282 -t public

If you already have apache or nginx running with PHP, you just need to point the root to public/index.php

Run tests

If you need to run Unit tests, just use the following command:

vendor/bin/phpunit

Issues installing composer and/or dependencies

You can get a ZIP with all dependencies already installed (just run a webserver and go inside the public folder). Download it here.

API

visualCaptcha, since 5.0, uses an API for increased security and to become back-end-agnostic (that's why you can easily plug-in a Vanilla JS, AngularJS, or jQuery front-end without changing anything).

It expects the following routes to exist, which we've put in this sample, using Slim (just to make it easier).

You are expected to have these routes in your implementation, but you can change them in visualCaptcha's front-end config.

GET /start/:howmany

This route will be the first route called by the front-end, which will generate and store session data.

Parameters:

GET /image/:index

This route will be called for each image, to get it and show it, by index.

Parameters:

GET /audio(/:type)

This route will be called for the audio file, to get it and play it, either the mp3 or ogg file.

Parameters:

POST /try

This is just a sample route, where we post the form to, and where the visualCaptcha validation takes place.

License

MIT. Check the LICENSE file.