Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2024-01-09 (9 months ago) | | 52% | | Total: 816 | | All time: 4,227 This week: 40 |
|
Description | | Author |
This class can perform CAPTCHA validation based on user clicks on circles.
It render an image with several circles on random positions. Only one circle appears cut.
The class performs CAPTCHA validation by checking the position where the user clicks on the image to verify it it is inside of the circle that is cut.
The generated image is served in PNG format. The values of the rendered circles are stored in session variables for subsequent validation.
The size and colors of the image and the circles are configurable parameters. | |
|
|
Innovation award
Nominee: 8x |
|
Example
<?php
declare(strict_types=1);
use OneClickCaptcha\Service\OneClickCaptchaServiceFactory;
include __DIR__ . '/../vendor/autoload.php';
ini_set('display_errors', '1');
error_reporting(E_ALL);
$OneClickCaptchaServiceFactory = new OneClickCaptchaServiceFactory();
$oneClickCaptcha = $OneClickCaptchaServiceFactory->getOneClickCaptcha();
// simple demonstration!
$request = $_GET['get_captcha'] ?? '';
if ($request === 'true') {
try {
$oneClickCaptcha->showCaptcha();
} catch (Exception $e) {
echo $e->getMessage();
}
} elseif (isset($_REQUEST['position'][0], $_REQUEST['position'][1])) {
if ($oneClickCaptcha->validate((int)$_REQUEST['position'][0], (int)$_REQUEST['position'][1])) {
echo '<h3>You are human!!</h3>';
} else {
echo '<h3>Wrong!</h3>';
}
}
// this is all html you need to validate captcha
echo '
<form action="example.php" method="POST">
<input type="image" src="example.php?get_captcha=true" name="position[]"/>
</form>
';
|
Details
OneClick captcha
This lib can perform CAPTCHA validation based on user clicks on circles.
It render an image with several circles on random positions. Only one circle appears cut.
The class performs CAPTCHA validation by checking the position where the user clicks on the image to verify it it is inside of the circle that is cut.
The generated image is served in PNG format. The values of the rendered circles are stored in session variables for subsequent validation.
The size and colors of the image and the circles are configurable parameters.
1. install using composer
composer require krowinski/one-click-captcha
2. example
include __DIR__ . '/../vendor/autoload.php';
error_reporting(E_ALL);
$OneClickCaptchaServiceFactory = new \OneClickCaptcha\Service\OneClickCaptchaServiceFactory();
$oneClickCaptcha = $OneClickCaptchaServiceFactory->getOneClickCaptcha();
// simple demonstration!
$request = isset($_GET['get_captcha']) ? $_GET['get_captcha'] : '';
if ($request === 'true') {
$oneClickCaptcha->showCaptcha();
} else {
if (isset($_REQUEST['position'][0], $_REQUEST['position'][1])) {
if (true === $oneClickCaptcha->validate($_REQUEST['position'][0], $_REQUEST['position'][1])) {
echo '<h3>You are human!!</h3>';
} else {
echo '<h3>Wrong!</h3>';
}
}
}
// this is all html you need to validate captcha
echo '
<form action="example.php" method="POST">
<input type="image" src="example.php?get_captcha=true" name="position[]"/>
</form>
';
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.