Ver Mensaje Individual
  #12 (permalink)  
Antiguo 23/03/2010, 09:28
DavidBL
 
Fecha de Ingreso: diciembre-2009
Ubicación: España
Mensajes: 380
Antigüedad: 14 años, 4 meses
Puntos: 1
Respuesta: Ayuda problema de libro de visitas

Vamos a ver, tengo el código de captcha pero me gustaría saber como añadirlo al libro de visitas.
Creo que hay que modificar el codigo de firmar.php y el de libro.php introduciendo algo de contacto.php
Gracias adlantadas
Codigo de firmar.php:
Cita:
<html><head></head><body><?php
$pvm = getdate();
$archivo="libro.txt"; #aquí para cambiar la ruta del archivo donde se guardan las entradas
$uusi="<table border=0 width=95% cellspacing=1><tr><td width=30%><b>Nombre :</b></td><td width=70%> $nombre </td></tr><tr><td width=30%><b>Fecha : </b></td><td width=70%>$pvm[mday]-$pvm[mon]-$pvm[year]</td></tr><tr><td width=30%><b>E-mail :</b></td><td width=70%><a href='mailto:$email'><font color='000000'>$email</font></a></td></tr><tr><td width=30%><b>Comentario :</b></td><td width=70%> $comentario </td></tr></table><hr width=70%>\n\n";
$fp=fopen($archivo, "r+");
$vanha=fread($fp, filesize($archivo));
fseek($fp, 0);
fwrite($fp, "${uusi}${vanha}");
fclose($fp);

print "<b>Gracias por firmar !!</b><br>";
print "<a href=libro.php>Regresar</a>";
?></body></html>
Codigo de libro.php:
Cita:
<div align="center"><strong><a href="#firmar">.: Firma el libro de visitas :.</a></strong><br><br>
<?php include("libro.txt"); #aquí para cambiar la ruta del archivo que muestra las entradas
?>
<br>
</div>
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td width="16%" align="center" valign="top">
<p align="center"><strong>.: Firmar :.<a name="firmar"></a></strong></p>
<table width="90%" cellspacing="1" cellpadding="1">
<tr>
<td align="left">
<?php
print "<table border=0 width=95% cellspacing=1>
<form method='post' action='firmar.php'>
<tr><td width=30%><b>Nombre :</b></b></td><td width=70%><input name=nombre maxlenght=30 type=text></td></tr>
<tr><td width=30%><b>Email(Optativo) :</b></td><td width=70%><INPUT name=email type=text></td></tr>
<tr><td width=30%><b>Comentario :</b></td><td width=70%><textarea name=comentario rows=5 cols=23></textarea>
<input type=submit value=Enviar></td></tr>
</form></table>";
?>
</td>
</tr>
</table>
<div align="center"></div></td>
</tr>
</table>

<p>&nbsp; </p>
<p align="left"><br>
Codigo captcha.php
Cita:
<?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);
?>
Codigo contacto.php
Cita:
<?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>