Bonsoir,
Je conçu un site en php. Dans lequel les visiteurs peuvent laisser des commentaires. Et pour ça il doivent remplir un petit formulaire qui contient un captcha. Ce captcha je l'ai réalisé à l'aide de Zend. Je fais un test, si le captcha saisit par l'internaute est correcte alors ça n'affiche rien sinon ça affiche le message suivant :Et j'ai toujours le message comme quoi le captcha n'est pas correct pourtant je rentre bien le bon captcha.'le captcha n'est pas correct'.
Voici mon code de mon formulaire
Le code qui enregistre mon commentaire:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <form action="fiche_question.php?id='.$_GET['id'].'" method="post" name="form_commentaire" style="width:150px"> <fieldset><legend>Commentaire</legende> <table> <tr> <th>NOM:</th> <td><input type="text" name="nom" size="39" value="'.$nom.'"></td> </tr> <tr> <th valign="top">Commentaire:</th> <td><textarea name="commentaire" rows="10" cols="30">'.$commentaire.'</textarea></td> <input type="hidden" name="id" value="'.$_GET['id'].'"> </tr>'; ?> <tr> <td>CAPTCHA</td> <td><img src="<?php echo '/la sequence doc' . $captcha->getImgUrl () . $captcha->getId()?>.png"/></td> </tr> <tr> <td><input type="hidden" name="captcha[id]" value="<?php echo $captcha->getId() ?>" size="40" /></td> <td><input type="text" name="captcha[input]" size="40" /></td> </tr> <tr> <td><input type="submit" value="valider" name="submit"></td> </tr> </table> </fieldset> </form>
Le code qui pour le captcha
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 if(empty($_POST['nom'])||empty($_POST['commentaire'])||empty($_POST['captcha'])) { echo "Veuillez renseigner tous les champs svp."; } if (!isset($_POST['captcha'])) { $captcha->generate(); } else { if ($captcha->isValid($_POST['captcha'])){ //echo '<img src="ok.gif" />'; $captcha->generate(); }else{ $captcha->generate(); //echo '<img src="ko.png"/>'; echo "Le captcha n\'est pas correct"; //echo var_dump($_POST['captcha']);die(); //echo $captcha->generate(); } } if(!empty($_POST['nom'])||(!empty($_POST['commentaire']))||(!empty($_POST['captcha']))) { if ($captcha->isValid($_POST['captcha'])) { $insert=('INSERT INTO commentaires(NOM,LEGENDE,IDARTICLES) VALUES("'.$_POST['nom'].'","'.$_POST['commentaire'].'",'.$_POST['id'].')'); header('location:fiche_question.php?id='.$_POST['id']); $execute=mysql_query($insert); } }
Je ne vois pas pourquoi ça ne fonctionne pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 include('../library/Zend/Loader/Autoloader.php'); Zend_Loader_Autoloader::getInstance()->registerNamespace('Zend_'); $captcha = new Zend_Captcha_Image(); $captcha->setDotNoiseLevel(4) ->setLineNoiseLevel(6) ->setTimeout("300") ->setExpiration("4") ->setWordLen(5) ->setFontSize(30) ->setHeight(80) ->setWidth(300) ->setFont($_SERVER['DOCUMENT_ROOT'] . "la sequence doc/font/arial.ttf") ->setImgDir($_SERVER['DOCUMENT_ROOT'] . "la sequence doc/images/captcha"); $captcha->generate();
Merci d'avance pour vos réponse.
Partager