Bonjour à tous, j'ai placé un captcha sur un formulaire que je vérifie la page d'après. Le captcha s'affiche correctement mais PROBLEME, le captcha envoye par $_POST est toujours égal a $_SESSION meme si l'image générée avait un autre code, c'est incompréhensible...
captcha.php
index.html
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 <?php session_start(); $captcha=rand(10000,99999); $_SESSION['captcha']=$captcha; $img=imagecreate(70, 20); $bgc=imagecolorallocate($img, 0, 0, 0); $color=imagecolorallocate($img, 238, 238, 238); $gris=imagecolorallocate($img, 128, 128, 128); imagefilledrectangle($img, 0, 0, 70, 20, $bgc); imagestring($img, 5, 13, 2, $captcha, $color); for($i=0;$i<150;$i++){ imagesetpixel($img, rand(0,70), rand(0,20), $gris); } header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header("Content-type: image/jpeg"); imagejpeg($img,'',20); imagedestroy($img); ?>
login.php
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 <html> <head> <title>Test</title> </head> <body> <form action="login.php" method="post"> <input type="submit" value="Connexion" /> <img src="captcha.php" /> <input type="text" name="captcha" maxlength="15" /> </form> </body> </html>
captcha.php et index.html fonctionne mais login.php affiche toujours que $captcha est égal à captchavalide peu importe ce qu'on post.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <?php session_start(); $captcha=trim($_POST['captcha']); $captchavalide=$_SESSION['captcha']; if($captcha==$captchavalide){ echo $captcha.'=='.$captchavalide; } else{ echo $captcha.'!='.$captchavalide; } ?>
Bien sur en local ca marche avec Easy PHP...
Quelqu'un a une idée ?
Partager