Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/05/2008, 10:57
nightduke
 
Fecha de Ingreso: mayo-2008
Mensajes: 181
Antigüedad: 16 años
Puntos: 0
Pregunta captcha no funciona...

Tengo este codigo de formulario, pero el captcha no me funciona....

¿Alquien sabe porque?
Si abro el fichero captcha.php me sale este error....

Fatal error: Call to undefined function: imagecreatetruecolor() in c:\var\internet\dominios\dominio.com\captcha.php on line 9
Gracias

<?php
session_start();
if(isset($_POST['enviar'])) {
$Message = "";
$Captcha = (string) $_POST["CAPTCHA_CODE"];
if($_POST['nombre'] == '') {
echo "<p style='color: #ff0000;'><strong>No has ingresado tu Nombre.</strong></p>";
}elseif($_POST['email'] == '') {
echo "<p style='color: #ff0000;'><strong>No has ingresado tu Email.</strong></p>";
}elseif($_POST['asunto'] == '') {
echo "<p style='color: #ff0000;'><strong>No has ingresado el Asunto del mensaje.</strong></p>";
}elseif($_POST['mensaje'] == '') {
echo "<p style='color: #ff0000;'><strong>No has ingresado el Mensaje.</strong></p>";
}elseif(sha1($Captcha) != $_SESSION["CAPTCHA_CODE"]) {
$Message = "<p style='color: #ff0000;'><strong>El c&oacute;digo de validaci&oacute;n no ha sido ingresado o es incorrecto.</strong></p>";
}else {
mail ("[email protected]", "$asunto", "$mensaje", "From: $nombre <$email>"); // coloque aqui su correo
echo '<p style="color: #63A915;"><strong>El email ha sido enviado con éxito.</strong></p>';
}
}
if(!empty($Message)) {
// Muestro los posibles errores de validación previos.
echo "$Message";
}
// Si aún no se han enviado los datos, mostramos el formulario
?>
<form method="post" action="contacto.php">
<label>Nombre / Nick:</label>
<input type="text" name="nombre" />
<label>Email:</label>
<input name="email" type="text" size="45" />
<label>Asunto:</label>
<input name="asunto" type="text" size="60" />
<label>Mensaje:</label>
<textarea name="mensaje" cols="80" rows="10"></textarea>
<label>Código de seguridad:</label>
<img src="captcha.php" /><input type="text" name="CAPTCHA_CODE" style="width: 50px;" />
<p style="padding-top: 5px;">
<input type="submit" name="enviar" value="Enviar Mensaje" />
<input type="reset" name="enviar" value="Borrar datos" />
</p>
</form>

captcha.php

<?php
session_start();

// Genero el codigo y lo guardo en la sesión para consultarlo luego.
$captchaCode = substr(sha1(microtime() * mktime()), 0, 6);
$_SESSION['CAPTCHA_CODE'] = sha1($captchaCode);

// Genero la imagen
$img = imagecreatetruecolor(70, 25);

// Colores
$bgColor = imagecolorallocate($img, 230, 230, 230);
$stringColor = imagecolorallocate($img, 90, 90, 90);
$lineColor = imagecolorallocate($img, 245, 245, 245);

// Fondo
imagefill($img, 0, 0, $bgColor);

imageline($img, 0, 5, 70, 5, $lineColor);
imageline($img, 0, 10, 70, 10, $lineColor);
imageline($img, 0, 15, 70, 15, $lineColor);
imageline($img, 0, 20, 70, 20, $lineColor);
imageline($img, 12, 0, 12, 25, $lineColor);
imageline($img, 24, 0, 24, 25, $lineColor);
imageline($img, 36, 0, 36, 25, $lineColor);
imageline($img, 48, 0, 48, 25, $lineColor);
imageline($img, 60, 0, 60, 25, $lineColor);

// Escribo el código
imageString($img, 5, 8, 5, $captchaCode, $stringColor);

// Image output.
header("Content-type: image/png");
imagepng($img);
?>