Captcha
Sou iniciante em php, to tentando fazer esse captcha funcionar, mas ta dificil!!
Ele não da nem um erro php, mas, eu digito os numeros e letras normalmente, mas quando clica em enviar, não importa se ta correto ou errado o javascript fala que ta errado! =\
Não sei oque pode ser.
Formulario
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript"><!--
function ValidaForm()
{
captcha = "<?php echo $chave; ?>";
if (document.forms[0].captcha.value != captcha) {
alert("Código de verificação incorreto, favor tentar novamente");
return false;
}
}
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');} }
//-->
</script>
</head>
<body>
<p><form id="form1" name="form1" method="post" action="gerador.php" onsubmit="return ValidaForm()">
Digite o código ao lado:
<input type="text" name="captcha" id="captcha" />
<img src="captcha.jpg" width="130" height="20" border=0 />
<input type="submit" value="Validar">
</form></p>
</body>
</html>gerador.php ( eu vo por mais coisa nesse gerar.php caso funciona o captchar, por isso deixei ele pequeno )
<?php
require ("Capctharimage.php");
require ("Captchar.php");
?>
Captchar.php
<?php
function chave($t)
{
$car = "1234567890abcdefghijklmnopqrstuvwxyz";
for ($i = 0; $i < $t; $i++) {
$chave .= $car{rand(0, strlen($car) - 1)};
}
return $chave;
}
?>
Capctharimage.php
<?php
function criaimagem()
{
global $chave;
$chave = chave(8);
$img = ImageCreate(130,20);
$fundo = ImageColorAllocate($img,0,0,0);
$texto = ImageColorAllocate($img,255,255,255);
ImageString($img,5,23,2,$chave,$texto);
ImageJpeg($img,"captcha.jpg");
}
criaimagem();
?>
Não sei oque pode ta havendo, pois sou iniciante em tudo. Agradeceria se alguem me desse um toque onde poderia está o possivel erro, obrigado
Discussão (2)
Carregando comentários...