1
<?php
2
/**
3
* Get an auto-generated question and answer for use with checking for human-ness.
4
* There are more sure-fire way to do this (cpatcha), but this is simple for the
5
* time being, and will probably block 99.9% of spam.
6
* @return array A two element array containing a question and answer, respectively
7
*/
8
function math_anti_spam_function() {
9
$operators = array('add', 'sub', 'mult', 'div');
10
$op = $operators[array_rand($operators)];
11
$ops = array (
12
'add' => array('+', 'plus'),
13
'sub' => array('-', 'minus'),
14
'mult'=> array('*', 'times'),
15
'div' => array('/', 'divided by', '÷')
16
);
17
18
$operator = $ops[$op][array_rand($ops[$op])];
19
20
if($op == 'add') {
21
$a = rand(0, 10);
22
$b = rand(0, 10);
23
$test = array ("What is $a $operator $b?", ($a + $b));
24
} elseif($op == 'sub') {
25
$a = rand(0, 10);
26
$b = rand($a, 10 + $a);
27
$test = array ("What is $b $operator $a?", ($b - $a));
28
} elseif($op == 'mult') {
29
$a = rand(0, 5);
30
$b = rand(0, 5);
31
$test = array ("What is $a $operator $b?", ($a * $b));
32
} elseif($op == 'div') {
33
$a = rand(1, 5);
34
$b = rand(0, 5);
35
$r = $a * $b;
36
$test = array ("What is $r $operator $a?", ($r / $a));
37
}
38
39
return $test;
40
}
41
42
/* End of file: ./system/functions/math_anti_spam_function.php */
43
Page URI: http://www.infopotato.com/index.php/code/function/math_anti_spam/
