Umm ya se crea un documento php llamado img.php con el siguiente codigo:
Código PHP:
header("Content-type: image/gif");
include "funciones.php";
captcha();
Luego tu archivo funciones.php debe quedar asi:
Código PHP:
function randomText($length) {
$pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
for($i=0;$i<$length;$i++) {
$key .= $pattern{rand(0,35)};
}
return $key;
}
/**
* crea un captcha
*
* @return image
*/
function captcha(){
session_start();
$_SESSION['tmptxt'] = randomText(8);
$captcha = imagecreatefromgif("http://www.forosdelweb.com/images/bgcaptcha.gif");
$colText = imagecolorallocate($captcha, 0, 0, 0);
imagestring($captcha, 5, 16, 7, $_SESSION['tmptxt'], $colText);
return imagegif($captcha);
}
Y tu archivo de formulario seria:
Código PHP:
<div class="paginacion"><? echo $links;?></div>
<?
$imagen="img.php";
?>
<br>Dejanos tu mensaje:<br><br>
<form action="" method="post">
Email: <input name="email" type="text" value="<? echo $_REQUEST['email']; ?>"><br><br>
Nombre: <input name="nombre" type="text" value="<? echo $_REQUEST['nombre']; ?>"><br><br>
Mensaje:<br><br>
<textarea rows="10" cols="30" name="texto"><? echo $_REQUEST['texto']; ?></textarea><br>
<img src="<? //echo $imagen; ?>" width="100" height="30"><br><br>
Ingrese codigo de seguridad:<br><br>
<input name="tmptxt" type="text"><br><br>
<input name="btget" type="submit" value="Verificar Codigo">
<input name="action" type="hidden" value="checkdata">
</form>
<?
//session_start();
if ($_POST['action'] == "checkdata") {
if ($_SESSION['tmptxt'] == $_POST['tmptxt']) {
$mensaje=nuevoMensaje($_REQUEST['email'],$_REQUEST['nombre'],$_REQUEST['texto']);
if(!empty($mensaje)){
if($mensaje[0]==1){?>
<div id="error">
<? echo $mensaje[1];?>
<a href="index.php?modulo=mensajes">Volver</a>
</div>
<?
}
else{
if($mensaje[0]==0){?>
<div id="ok">
<? echo $mensaje[1];?>
<a href="index.php">Volver</a>
</div>
<? }
}
}
}
}?>
</div>
Si tienes problemas con la sessiones escribeme.
Espero te ayude :)