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
| <?php
session_start();
$colors = array('yellow', 'green', 'blue', 'red', 'gray', 'pink', 'black');
$couleurs = array('jaune', 'vert', 'bleu', 'rouge', 'gris', 'rose', 'noir');
$i = mt_rand(0, count($colors)) - 1;
$color = $colors[$i];
$code = $couleurs[$i];
$captcha = '<div style="width:20px;"><div style="float:right;width:20px;height:20px;background-color:'.$color.'"></div></div>';
if (isset($_POST['color'], $_SESSION['color'])) {
if ($_POST['color'] == $_SESSION['color']) {
echo 'OK';
}
else {
echo 'Error<br><br>';
echo 'post: '.$_POST['color'].'<br>';
echo 'sess: '.$_SESSION['color'];
}
}
unset($_SESSION['color']);
$_SESSION['color'] = $code;
?>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
<input style="width:66px" type="submit" name="envoye" value="Envoyer" />
<input style="width:66px" type="reset" name="annuler" value="Annuler" />
Quelle est cette couleur?
<?php echo $captcha; ?>
<input class="form" style="width:75px" type="text" id="color" name="color" value="" size="10" />
</form> |