Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/01/2008, 17:01
Avatar de neodani
neodani
 
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 2 meses
Puntos: 20
Problema con CAPTCHA

Que no hay manera que me vaya el CAPTCHAaaaaaaaaaa

Tengo lo que genera el captcha.php

CAPTCHA.PHP

Código PHP:
<?php
//Start the session so we can store what the code actually is.
session_start();

//Now lets use md5 to generate a totally random string
$md5 md5(microtime() * mktime());

/*
We dont need a 32 character long string so we trim it down to 5
*/
$string substr($md5,0,5);

/*
Now for the GD stuff, for ease of use lets create
 the image from a background image.
*/

$captcha imagecreatefrompng("captcha.png");

/*
Lets set the colours, the colour $line is used to generate lines.
 Using a blue misty colours. The colour codes are in RGB
*/

$black imagecolorallocate($captcha000);
$line imagecolorallocate($captcha,233,239,239);

/*
Now to make it a little bit harder for any bots to break, 
assuming they can break it so far. Lets add some lines
in (static lines) to attempt to make the bots life a little harder
*/
imageline($captcha,0,0,39,29,$line);
imageline($captcha,40,0,64,29,$line);

/*
Now for the all important writing of the randomly generated string to the image.
*/
imagestring($captcha52010$string$black);

/*
Encrypt and store the key inside of a session
*/

$_SESSION['key'] = md5($string);

/*
Output the image
*/
header("Content-type: image/png");
imagepng($captcha);
?>
Si lo ejecuto me sale bien la imagen.
En teoria esto se guarda en una variable de sesion llamada $_SESSION['key'] no??

Luego tengo mi formulario. (No hace falta que tenga ningun "session start() verdad?)

FORMULARIO
Código HTML:
<form id="formulario" method="post" action="includes/validar.php">
	<label for="captcha">Codigo de seguridad: *</label>
	<img id="cap" name="cap" src="captcha.php">

	<label for="captcha">Repite el Código de seguridad:</label> 
	<input type="text" name="captcha_code" style="width: 150px;">

	<label for="send"></label>
	<input id="send" name="send" value="Registrarme!" type="submit" />
</form> 
Y entonces en mi script de validar.php

VALIDAR.PHP
Código PHP:
<?php
session_start
();
if (
$_SESSION['key'] != $_POST['captcha_code']) {
    echo 
"CODIGO ERRONEO";
}
else{
    echo 
"CODIGO CORRECTO";
}
?>
No encuentro porqué me dice que el codigo es erroneo!

Es normal que en la variable de $_SESSION['key'] se guarde un numero la tira de largoooooooo, no debería aparecer ahi el valor del captcha?

Ayuda pliss