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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
<?php
$question = rand(0,11);
$captchas_question = 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_reponse = array(3,5,8,5,7,10,1,12,7,8,1,5);
$tricheur = false;
$pas_de_reponse = false;
if (isset($_POST['captcha']))
{
$questionIni = $_POST['captcha'];
if (in_array($questionIni,$captchas_question))
{
if (isset($_POST['reponse']))
{
$ok = false;
$reponse = $_POST['reponse'];
foreach($captchas_question as $key => $value)
{
if ($value == $questionIni) {
if ($captchas_reponse[$key] == $reponse )
{
$ok = true;
}
}
}
}
else
{
$pas_de_reponse = true;
}
}
else
{
$tricheur = true;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
</style>
<script>
</script>
</head>
<body>
<?php
if (isset($ok))
{
if (!$tricheur && !$pas_de_reponse)
{
if ($ok)
{
print "Réponse ok<br>";
}
else
{
print "Réponse ko<br>";
}
}
else
{
if ($tricheur) {
print "Petit malin !!!<br>";
}
if ($pas_de_reponse) {
print "Il faut donner une réponse !!!<br>";
}
}
}
else
{
$ok = false;
}
if (!$ok)
{?>
<form action="test9331b.php" method="post">
<!-- label avec la question de la réponse -->
<label for="reponse">
<?php if(isset($_POST["question"])){
echo($_POST["question"]);}
else{$_POST["question"]=$captchas_question[$question];
echo($_POST["question"]);
}
?>
</label><br>
<input type="hidden" name="captcha" value="<?php print $captchas_question[$question];?>"/>
<!-- input réponse -->
<input type="text" name="reponse"><br/>
<input type="submit" name="sbm" value="Envoyer"/>
</form><?php
}
?>
</body>
</html> |