variable de session (synchronisation)
Bonsoir,
J'ai un formulaire dont je vérifie les champs dans la même page, pour la majorité des champs ça marche bien mais j'ai un problème pour vérifier le captcha. En effet, dans mon formulaire j'affiche l'image via un fichier php externe qui marche très bien, et dans ce fichier je mets le code du captcha dans une variable de session. Le problème c'est que lorsque j'affiche le code du captcha transmis, il me donne celui de la fois d'avant ( c'est à dire le code du captcha de la fois précedente, car il change à chaque actualisation. Je crois savoir que c'est à cause que les variables de session doivent exister avant leur création, car pour résoudre ce problème , il est possible de vérifier le captcha dans une autre page après le formulaire, mais cela ne m'interesse pas. Si quelqu'un connait l'astuce, j'en serais reconnaissant :roll:. Si ça peut aider, voici mon code :
Code:
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 99 100 101 102 103 104 105
|
<?php
session_start();
?>
<html>
<body>
<?php
if(empty($_POST["valider"])) //Si le bouton valider à été cliqué
{
?>
<form action="<? echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data" name="f1" >
<table border="0" cellpadding="5" cellspacing="0" width="137">
<tr>
<td>Nom:</td>
<td><input type="text" name="nom" size="20"></td>
</tr>
<tr>
<td>Prénom:</td>
<td><input type="text" name="prenom" size="20"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" size="25"></td>
</tr>
<tr>
<td>Objet</td>
<td><input type="text" name="objet" size="25"></td>
</tr>
<tr>
<td>Votre message</td>
<td><textarea rows="12" name="msg" cols="40"></textarea></td>
</tr>
<tr>
<td>CV:</td>
<td><input type="file" name="cv" value="ffff.pdf" size="40"></td>
</tr>
<tr>
<td>Lettre de motivation:</td>
<td><input type="file" name="lm" size="40"></td>
</tr>
<tr>
<td><img src="captcha.php" /></td>
<td><input type="text" name="codesaisie" /></td>
</tr>
<tr>
<td></select> <input type="submit" value="Envoyer" name="valider"></td></div>
</tr>
</table>
</form>
<p><center><font color="red">Veuillez remplir le deux champs</font></center></P>
<?php
$codeVrai = $_SESSION['captcha'];
}
else
{
?>
<form action="<? echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data" name="f1" >
<table border="0" cellpadding="5" cellspacing="0" width="137">
<tr>
<td>Nom:</td>
<td><input type="text" name="nom" value="<?php echo $_POST['nom'] ?>" size="20"></td>
</tr>
<tr>
<td>Prénom:</td>
<td><input type="text" name="prenom" value="<?php echo $_POST['prenom'] ?>" size="20"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" value="<?php echo $_POST['email'] ?>" size="25"></td>
</tr>
<tr>
<td>Objet</td>
<td><input type="text" name="objet" value="<?php echo $_POST['objet'] ?>" size="25"></td>
</tr>
<tr>
<td>Votre message</td>
<td><textarea rows="12" name="msg" value="<?php echo $_POST['msg'] ?>" cols="40"></textarea></td>
</tr>
<tr>
<td>CV:</td>
<td><input type="file" name="cv" value="<?php echo $_FILES['cv']['name'] ?>" size="40"></td>
</tr>
<tr>
<td>Lettre de motivation:</td>
<td><input type="file" name="lm" value="<?php echo $_FILES['lm']['name'] ?>" size="40"></td>
</tr>
<tr>
<td><img src="captcha.php" /></td>
<td><input type="text" name="codesaisie" /></td>
</tr>
<tr>
<td></select> <input type="submit" value="Envoyer" name="valider"></td></div>
</tr>
</table>
</form>
<?php
//récupération et affichage du captcha transmis
$codeVrai = $_SESSION['captcha'];
echo $codeVrai;
}
?>
</body>
</html> |