1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
session_start();
function captchaCalcul() {
$operators = array('-' => '-', '+' => '+', '*' => 'x');
$operator = array_rand($operators);
$op = $operators[$operator]; // on récupère l'opérateur de calcul
$num = array('Zero', 'Un', 'Deux', 'Trois','Quatre', 'Cinq', 'Six', 'Sept','Huit', 'Neuf', 'Dix');
$nb1 = array_rand($num);
$nb2 = array_rand($num);
if($operator === '-' && $nb1 < $nb2) {
while($nb1 < ($nb2 = array_rand($num))); // on évite les résultats négatif en cas de soustraction
}
eval('$_SESSION[\'captchaResult\'] = strval('.$nb1.$operator.$nb2.');');
return $num[$nb1]." <span class=\"gras\">".$op."</span> ".$num[$nb2];
} |
Partager