https://github.com/theodorejb/responsive-captcha
A PHP library for generating random, accessible arithmetic and logic questions
https://github.com/theodorejb/responsive-captcha
captcha php
Last synced: about 1 year ago
JSON representation
A PHP library for generating random, accessible arithmetic and logic questions
- Host: GitHub
- URL: https://github.com/theodorejb/responsive-captcha
- Owner: theodorejb
- License: mit
- Created: 2012-12-24T17:55:20.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2020-12-11T18:52:50.000Z (over 5 years ago)
- Last Synced: 2025-03-25T13:11:21.249Z (over 1 year ago)
- Topics: captcha, php
- Language: PHP
- Homepage:
- Size: 41 KB
- Stars: 12
- Watchers: 6
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Responsive Captcha
[](https://packagist.org/packages/theodorejb/responsive-captcha)
Prevent form spam by generating random, accessible arithmetic and logic questions.
Examples:
* "What is the fourth letter in snowboard?"
* "What is the sum of four and six?"
* "What is eight multiplied by two?"
* "Which is smallest: sixty-six, one hundred, or twenty-two?"
Users can respond with either the numeric or textual version of an answer (e.g. "16" or "sixteen").
For background info on this project, see my blog post: https://theodorejb.me/2012/12/30/responsive-captcha/
## Install via Composer
`composer require theodorejb/responsive-captcha`
## Usage
1. Generate a random question:
```php
use function theodorejb\ResponsiveCaptcha\{randomQuestion, checkAnswer};
$qa = randomQuestion();
$realAnswer = $qa->getAnswer(); // save somewhere (e.g. in session or encrypted single-use token)
```
2. Display question in form:
```html+php
= $qa->getQuestion() ?>
```
3. Check whether the user's response is correct:
```php
$answer = filter_input(INPUT_POST, "captcha");
if ($answer !== null) {
if (checkAnswer($answer, $realAnswer)) {
// code to execute if the captcha answer is correct
} else {
// the answer is incorrect - show an error to the user
}
}
```