InicioHazlo Tu MismoSistema de Captcha V.1 PHP

Hola, en este post el mostrare un sistema de Captcha con php.

Esto consiste de 4 archivos

1.- Alguna imagen GIF con nombre bgcaptcha que el fondo no sea negro
2.- Archivo styles.css
3.- Archivo captchademo.php
4.- Archivo captcha.php

Codigos:
styles.css
dijo:


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;
}



Archivo captchademo.php:

dijo:


<?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:

dijo:

<?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);
?>



Esto es todo, luego para indicar la acion que realizara si el captcha es correcto esta en el archivo captchademo.php al principio esta con if.
Saludos
Datos archivados del Taringa! original
0puntos
57visitas
0comentarios
Actividad nueva en Posteamelo
0puntos
2visitas
0comentarios
Dar puntos:

Dejá tu comentario

0/2000

Autor del Post

l
lebni🇦🇷
Usuario
Puntos0
Posts1
Ver perfil →
PosteameloArchivo Histórico de Taringa! (2004-2017). Preservando la inteligencia colectiva de la internet hispanohablante.

CONTACTO

18 de Septiembre 455, Casilla 52

Chillán, Región de Ñuble, Chile

Solo correo postal

© 2026 Posteamelo.com. No afiliado con Taringa! ni sus sucesores.

Contenido preservado con fines históricos y culturales.