PHP - Image Captcha: "bug"

Résolu
Bonjour,

J'ai un petit problème...
En effet j'ai crée mon image captcha, le formulaire, et la vérification du code, mais que la saisie soit correcte ou non, j'ai toujours faux.

Merçi d'avance.

Voiçi mes codes:

FORMULAIRE:
<form method="POST" action="traiter.php">
<h3>Quel est le chiffre ?</h3>
<img src="captcha.php" style="70px"/><br>
<input type="text" name="captcha" style="70px" />
<input type="submit" />
</form>


IMAGE:
<?php
 session_start();
 $_SESSION['captcha'] = rand (1000,9999);
 $img = imagecreatetruecolor(70, 30);
 $fill_color=imagecolorallocate($img,255,255,255);
 imagefilledrectangle($img, 0, 0, 70, 30, $fill_color);
 $text_color=imagecolorallocate($img,10,10,10);
 $font = "./monofont.ttf";
 imagettftext($img, 23, 0, 5, 30, $text_color, $font, $_SESSION['captcha']);
 header("Content-type: image/jpg");
 imagejpeg($img);
 imagedestroy($img);
 ?>


TRAITEMENT:
<?php
if ($_POST['captcha']){
  if ($_POST['captcha']==$_SESSION['captcha']){
	echo 'Bravo !';
  }
  else{
    echo 'Dommage !';
  }
 }
?>

4 réponses

  1. salut merci pour cette réponse
    ne pas oublier

    <?php session_start

    merci merci merCIIIIII!!!!
    1. Bonjour

      As-tu bien session_start() dans ton formulaire et traitement aussi ?
      Dans ton traitement, affiche les valeurs de $_POST['captcha']et de $_SESSION['captcha'] pour voir laquelle des deux n'est pas correcte.