Hi i want to create a image captcha with php, i have the next code for my form.
<form action="" method="POST">
<div class="label_form">Usuario:</div> <input type="text" name="user"/><br>
<div class="label_form">Contraseña:</div> <input type="password" name="pass"/><br>
<img alt="Numeros aleatorios" src="layouts/captcha.php" />
<input class="label_form" type="text" name="num"/><br>
<input type="submit" value="ENTRAR" name="submit"/>
</form>
This is the code for validation before to send the form:
if (isset($_POST["submit"])) {
if ($_SESSION['img_number'] != $_POST['num']) {
echo "<div class='msg_error'>Los caracteres no se corresponden.</div>";
} else {
/*DO STUFF*/
}
}
And in other file with the name captcha.php i have the code phpfor generate the image:
header("Content-type: image/png");
$string = "abcdefghijklmnopqrstuvwxyz0123456789";
for ($i = 0; $i < 5; $i++) {
$pos = rand(0, 36);
$str. = $string {
$pos
};
}
$img_handle = ImageCreate(60, 22) or die("Es imposible crear la imagen");
$back_color = ImageColorAllocate($img_handle, 102, 102, 153);
$txt_color = ImageColorAllocate($img_handle, 255, 255, 255);
ImageString($img_handle, 31, 5, 0, $str, $txt_color);
Imagepng($img_handle);
session_start();
$_SESSION['img_number'] = $str;
This give a image broken showing the alt from img "Numeros aleatorios", so that tell me the file.php is calling fine the img but the code for generated is not working, any help is gratefull :D thanks.

