1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| <?php
function check_captcha()
{
// si posté, on récupère, sinon, valeur aléatoire
$captcha_q = (!empty($_POST['captcha_q']))? $_POST['captcha_q'] : rand(0,11);
$captcha_r = (!empty($_POST['captcha_r']))? $_POST['captcha_r'] : '';
$captchas_q = array(
"deux plus un",
"trois + deux",
"cinq plus trois",
"six moins un",
"six plus un",
"cinq fois deux",
"trois moins deux",
"six fois deux",
"trois plus quatre",
"quatre fois deux",
"deux moins un",
"trois plus deux"
);
$captchas_r = array(
3,
5,
8,
5,
7,
10,
1,
12,
7,
8,
1,
5
);
$captcha_return = array();
$captcha_return['succes'] = false;
if( !empty($_POST['captcha_r']) && is_numeric($_POST['captcha_r']) ) // on attend une valeur numerique (entier)
{
if( $_POST['captcha_r'] == $captchas_r[$captcha_q] )
{
$captcha_return['succes'] = true;
}
}
$captcha_return['captcha_q'] = $captcha_q;
$captcha_return['captcha_q_libelle'] = $captchas_q[$captcha_q];
// -------------
return $captcha_return; // retourne un array (contenant plusieurs valeurs, qui seront utiles dans le formulaire)
} |