. FKE Internet - Hosting the Future FKE Internet - Hosting the Future FKE Internet - Hosting the Future  

HumanMathTest Class Test Fixture


HumanMathTest implements a math test 'bot deterrent PHP class for use in online forms, written and Copyright 2018 by Fred Koschara, and released under the terms of the BSD-3-clause license. It can be downloaded by clicking the Download button at the upper right corner of this page. The ZIP file includes the source code for the simple example page, this page (which illustrates using many of the options available), and the fully documented implementation HumanMathTest.php file.

This class is used to create an image to be included in an online form that shows a simple math test the visitor must solve when submitting the form. The operands and operation are stored in the $_SESSION data for the page. After submitting the form, the visitor's answer is checked by calling the verify() method to compare their entry vs. the session data. If an error is found, the form submission should be rejected.

Limitations and Scope

One problem with this sort of form protection is that the math problems need to be very simple for average users to succeed. Answers are limited to integers in the 0-99 range so that users can calculate them. Even without using optical character recognition to parse the image and calculate the correct answer, a bot attempting numerous trials will succeed with a small but harmful percentage once it knows the field requires numeric input and the valid range. This is a start but the challenge is to make it harder for bots to defeat while keeping it easy enough for humans of almost all capabilities to succeed.

Used in isolation, this test is far from adequate protection on a form where anything more than minimal security is needed because of the statistically high possibility of getting a correct answer from a random selection.

This class, as written, is intended to reduce noise submissions on a survey form, not to preventing someone from biasing the outcome.


Please consider supporting my work:

Email: foss (at) L5Software (dot) com


Plus Math Test question: what is two plus two? is
Times math test =
Minus Math Test question: what is nine minus seven? =>

   
Random math test equals

Default Math Test question: what is nine minus six? =

For Next Time:
These controls adjust the tests after form submission.
Plus  < default >
 < empty >
 Sorry, wrong answer!
 %s is not %d
 The answer %d is wrong
 Bad entry for %s
 < array value >
 < bogus empty value >
Minus   Change $tag test, see error log
Times  Normal      Big      Narrow      Tiny      Error
Random  Plus/Minus      Plus/Times      Times/Minus      All Operators      Error
 

$plusTest: Valid L5Software\FormTools\HumanMathTest instance
{	equation: 2 + 2 (two plus two)
	error message: "Your Math Test answer %d for %s is incorrect."
	operations enabled: add
	session data tag: FKE_HUMANMATHTEST_DATA_PLUS
	session has data: TRUE
	style:	Array
		(	[bkgnd] => none
			[color] => ffffff
			[font] => /web/Scripts/monofont.ttf
			[height] => 40
			[width] => 120
		)
	configured parameters:
		Array
		(	[errMsg] => Your Math Test answer %d for %s is incorrect.
			[operator] => OP_ADD
			[tag] => "PLUS"
		)
	active configuration:
		Array
		(	[errMsg] => Your Math Test answer %d for %s is incorrect.
			[operator] => OP_ADD
			[tag] => "PLUS"
		)
}
$timesTest: Valid L5Software\FormTools\HumanMathTest instance
{	equation: 4 x 6 (four times six)
	error message: "Your Math Test answer %d for %s is incorrect."
	operations enabled: multiply
	session data tag: FKE_HUMANMATHTEST_DATA_TIMES
	session has data: TRUE
	style:	Array
		(	[bkgnd] => ffffff
			[color] => 9d5907
			[font] => /web/Scripts/monofont.ttf
			[height] => 40
			[width] => 120
		)
	configured parameters:
		Array
		(	[operator] => OP_TIMES
			[tag] => "_TIMES"
		)
	active configuration:
		Array
		(	[operator] => OP_TIMES
			[tag] => "_TIMES"
			[errMsg] => Your Math Test answer %d for %s is incorrect.
		)
}
$minusTest: Valid L5Software\FormTools\HumanMathTest instance
{	equation: 9 - 7 (nine minus seven)
	error message: "Your Math Test answer %d for %s is incorrect."
	operations enabled: subtract
	session data tag: FKE_HUMANMATHTEST_DATA_MINUS
	session has data: TRUE
	style:	Array
		(	[bkgnd] => none
			[color] => ffffff
			[font] => /web/Scripts/monofont.ttf
			[height] => 40
			[width] => 120
		)
	configured parameters:
		Array
		(	[operator] => OP_MINUS
			[tag] => "MINUS"
		)
	active configuration:
		Array
		(	[operator] => OP_MINUS
			[tag] => "MINUS"
			[errMsg] => Your Math Test answer %d for %s is incorrect.
		)
}
$randTest: Valid L5Software\FormTools\HumanMathTest instance
{	equation: 1 + 1 (one plus one)
	error message: "%s does not equal %d"
	operations enabled: add,subtract
	session data tag: FKE_HUMANMATHTEST_DATA_RAND
	session has data: TRUE
	style:	Array
		(	[bkgnd] => 777
			[color] => ffffff
			[font] => /web/Scripts/monofont.ttf
			[height] => 40
			[width] => 120
		)
	configured parameters:
		Array
		(	[errMsg] => %s does not equal %d
			[operator] => (OP_ADD | OP_MINUS)
			[tag] => "RAND"
		)
	active configuration:
		Array
		(	[errMsg] => %s does not equal %d
			[operator] => (OP_ADD | OP_MINUS)
			[tag] => "RAND"
		)
}
$dfltTest: Valid L5Software\FormTools\HumanMathTest instance
{	equation: 9 - 6 (nine minus six)
	error message: "Your Math Test answer %d for %s is incorrect."
	operations enabled: add,multiply,subtract
	session data tag: FKE_HUMANMATHTEST_DATA
	session has data: TRUE
	style:	Array
		(	[bkgnd] => none
			[color] => ffffff
			[font] => /web/Scripts/monofont.ttf
			[height] => 40
			[width] => 120
		)
	configured parameters: NULL
	active configuration:
		Array
		(	[errMsg] => Your Math Test answer %d for %s is incorrect.
			[operator] => OP_ALL
			[tag] => ""
		)
}

Valid XHTML 1.0 Strict
Valid XHTML 1.0 Strict