Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/04/2008, 23:37
opzina
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
Re: (Ayuda) Incluir captcha en formulario

Lo que se me va ocurriendo es: poner en el archivo formulario.html el captcha y con el mismo boton que verifica que el texto del capcha ingresado es correcto (y si es correcto), envia el formulario....pero como relacion esto???

codigos:

captchademo.php

<?php
session_start();
if ($_POST['action'] == "checkdata") {
if ($_SESSION['tmptxt'] == $_POST['tmptxt']) {
echo "Bienvenido";
} else {
echo "Intentalo nuevamente";
}
exit;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CAPTCHA con PHP</title>
<meta name="description" content="CAPTCHA con PHP: ejemplo para demostrar la creacion de Captcha con PHP." />
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" class="descdet">
<div class="bordeder">
<strong class="subder">CAPTCHA con PHP </strong><br>
Ingresar el texto mostrado en la imagen <br>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<img src="captcha.php" width="100" height="30" vspace="3"><br>
<input name="tmptxt" type="text" size="30"><br>
<input name="btget" type="submit" class="boton" value="Verificar Codigo">
<input name="action" type="hidden" value="checkdata">
</form>
</div>
</td>
</tr>
</table>
</body>
</html>

Captcha.php

<?php
session_start();
function randomText($length) {
$pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
for($i=0;$i<$length;$i++) {
$key .= $pattern{rand(0,35)};
}
return $key;
}

$_SESSION['tmptxt'] = randomText(8);
$captcha = imagecreatefromgif("bgcaptcha.gif");
$colText = imagecolorallocate($captcha, 0, 0, 0);
imagestring($captcha, 5, 16, 7, $_SESSION['tmptxt'], $colText);

header("Content-type: image/gif");
imagegif($captcha);
?>


HOja de estilos: styles.css

body {
background-color: #FFFFFF;
text-align: center;
font-family: "Trebuchet MS", Tahoma, Verdana;
font-size: 12px;
font-weight: normal;
color: #6F6F6F;
text-decoration: none;
padding: 0px;
margin: 0px;
}
.title01 {
color: #CC0000;
text-decoration: none;
}
.title {
font-size: 24px;
font-weight: bold;
text-decoration: none;
font-family: "Trebuchet MS", Tahoma, Verdana;
border-bottom-width: 2px;
border-bottom-style: solid;
border-bottom-color: #A8A8A8;
padding: 0px;
background-image: url(images/bgsup.gif);
}
input {
font-family: "Trebuchet MS", Tahoma, Verdana;
font-size: 12px;
font-weight: normal;
color: #6F6F6F;
background-color: #FFFFFF;
border-top-width: 1px;
border-right-width: 2px;
border-bottom-width: 2px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #D4D0C8;
border-right-color: #A8A8A8;
border-bottom-color: #A8A8A8;
border-left-color: #D4D0C8;
padding-top: 2px;
padding-right: 3px;
padding-bottom: 2px;
padding-left: 3px;
}
.boton {
font-family: "Trebuchet MS", Tahoma, Verdana;
font-size: 12px;
font-weight: bold;
color: #FFFFFF;
background-color: #A8A8A8;
border-top-width: 1px;
border-right-width: 2px;
border-bottom-width: 2px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #D4D0C8;
border-right-color: #A8A8A8;
border-bottom-color: #A8A8A8;
border-left-color: #D4D0C8;
text-decoration: none;
padding-right: 10px;
padding-left: 10px;
cursor: pointer;
}
.descdet {
font-weight: normal;
color: #6F6F6F;
text-decoration: none;
font-size: 12px;
}
.namedet {
font-weight: bold;
color: #3354AA;
text-decoration: none;
font-size: 13px;
}
.paginate {
font-size: 12px;
text-decoration: none;
background-color: #F2F2F2;
border-left-width: 16px;
border-left-style: solid;
border-left-color: #FFFFFF;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 10px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #D4D0C8;
margin-bottom: 10px;
border-right-width: 16px;
border-right-style: solid;
border-right-color: #FFFFFF;
}
.supres1 {
font-size: 12px;
text-decoration: none;
background-color: #F2F2F2;
border-left-width: 12px;
border-left-style: solid;
border-left-color: #FFFFFF;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 10px;
border-bottom-width: 1px;
border-bottom-style: dashed;
border-bottom-color: #D4D0C8;
margin-bottom: 10px;
}
.supres2 {
font-size: 12px;
text-decoration: none;
background-color: #F2F2F2;
padding-top: 5px;
padding-bottom: 5px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #D4D0C8;
margin-bottom: 10px;
padding-right: 10px;
border-right-width: 13px;
border-right-style: solid;
border-right-color: #FFFFFF;
}
.copy {
font-size: 12px;
font-weight: normal;
color: #6F6F6F;
text-decoration: none;
padding-top: 5px;
padding-right: 16px;
padding-bottom: 5px;
padding-left: 16px;
border-top-width: 1px;
border-top-style: solid;
border-top-color: #A8A8A8;
}
.borde {
background-color: #F2F2F2;
border: 1px dashed #D4D0C8;
font-size: 12px;
text-decoration: none;
margin: 0px;
text-align: left;
padding: 5px;
width: 468px;
}
.bordeder {

background-color: #F2F2F2;
width: 310px;
border: 1px dashed #D4D0C8;
font-size: 12px;
text-decoration: none;
vertical-align: middle;
margin-top: 16px;
padding-top: 5px;
padding-bottom: 5px;
}
.subder {
font-size: 16px;
font-weight: bold;
text-decoration: none;
font-family: "Trebuchet MS", Tahoma, Verdana;
background-image: url(images/bgsup.gif);
color: #CC0000;
}

y faltaria la img....cualquier cosa la piden q la subo...

Gracias - salu2!