Aquí estan
register.php
captcha.php
register.php
Código (javascript) [Seleccionar]
<script type="text/javascript" src="sha1.js"></script>
<script type="text/javascript"> //Función para validar el formulario
function verificar_correo(texto)
{
var status = false;
var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
if (texto.search(emailRegEx) != -1)
{
status = true;
}
return status;
}
function validar()
{
var noerrors=1;
var charset="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
var usu1=document.registro.usuario.value;
var pas1=document.registro.pass.value;
var pas2=document.registro.pass2.value;
var email=document.registro.correo.value;
if (usu1.length>3)
{
for (i=0;i<usu1.length;i++)
{
if (charset.indexOf(usu1.charAt(i),0)==-1)
{
alert("The username only can contain alphanumeric characters [a-z,A-Z,0-9], dashes [-] and underscores [_].");
noerrors=0;
break;
}
}
}
else
{
alert("The username must be equal or longer than 4 characters.");
}
if (pas1!=pas2)
{
alert("The passwords doesn't match. Please, rewrite them.");
noerrors=0;
} else if (pas1.length<4 || pas2.length<4) { alert("Password must be equal or longer than 4 characters."); noerrors=0; }
if (!(verificar_correo(email))) { alert("The email that you wrote is invalid."); noerrors=0; }
var thecaptcha=<?php echo '"'.$_SESSION['captcha'].'"'; ?>; //aqui hay code php
if (thecaptcha!=document.registro.captchacode.value)
{
alert(thecaptcha);
alert("Please, write again the captcha, you don't writted it properly.");
}
document.registro.js.value=1;
document.registro.pass=sha1(sha1(document.registro.pass.value));
document.registro.pass2=sha1(sha1(document.registro.pass2.value));
if (noerrors==1) { document.registro.submit(); }
}
</script>
<img src="captcha.php">
captcha.php
Código (php) [Seleccionar]
<?php
$numcaracteres=8;
session_start();
$caracteres = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$codigo = '';
$i = 0;
while ($i < $numcaracteres)
{
$codigo .= substr($caracteres, mt_rand(0, strlen($caracteres)-1), 1);
$i++;
}
$ancho = 300;
$alto = 60;
$imagen = ImageCreate($ancho, $alto);
$color1 = ImageColorAllocate($imagen, 0, 0, 0); // negro
$color2 = ImageColorAllocate($imagen, 124, 159, 191); // azul
$color3 = ImageColorAllocate($imagen, 255, 0, 0); //rojo
ImageFill($imagen, 0, 0, $color2);
ImageString($imagen, 5, 150, 30, $codigo, $color1);
imageline($imagen, 0, 5, $ancho, 5, $color1);
imageline($imagen, $ancho/4, 0, $ancho/2, $alto, $color1);
imageline($imagen, 0, 18, $ancho, 18, $color1);
imageline($imagen, 46, 0, 86, $alto, $color1);
header("Content-Type: image/png");
ImagePng($imagen);
$_SESSION["captcha"] = $codigo;
ImageDestroy($imagen);
?>