Re: [PHP] Re: Codigo de Captcha en PHP

2006-08-15 Thread Julio B.
Hi Richard, my example is not safe, but already I wrote in the last part of 
my message to Ricardo that, by security, would be necessary to make use of 
session variables, for example, to pass the value of catpcha generated and 
to be able to compare it.

The modification would be like this:

?php
session_start();
$key = strtolower(substr(md5(rand()), 0, 4));
$_SESSION['captcha'] = $key;

 $im = imagecreatetruecolor(40, 20);

 $bg = imagecolorallocate($im, 0, 0, 0);
 $col_text = imagecolorallocate($im, 255, 255, 255);

 imagestring($im, 4, 4, 1, $key, $col_text);

 header('Content-type: image/png');
 imagepng($im);
 imagedestroy($im);

?

And the comparison would be between the value introduced by the user and the 
stored one in the session variable.

Saludos,

Julio Barroso 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Codigo de Captcha en PHP

2006-08-14 Thread Julio B.
Hay muchos y muy variados en Internet. En alguna ocasión he usado el que 
viene en sBlog. Es muy sencillo de implementar y para la mayoría de los 
casos suficiente para evitarnos problemas de spam.

En código es:

?php

 $key = (array_key_exists('k', $_GET)  strlen($_GET['k']) == 4) ? 
$_GET['k'] : strtolower(substr(md5(rand()), 0, 4));

 $im = imagecreatetruecolor(40, 20);

 $bg = imagecolorallocate($im, 0, 0, 0);
 $col_text = imagecolorallocate($im, 255, 255, 255);

 imagestring($im, 4, 4, 1, $key, $col_text);

 header('Content-type: image/png');
 imagepng($im);
 imagedestroy($im);

?

Luego llamas a este archivo desde el que lo necesites.

Te generas el código (en este caso de 4 numeros y letras):

?php   $k = strtolower(substr(md5(mt_rand()), 0, 4)); ?

En el formulario donde lo uses poner un campo oculto como éste:

input type=hidden name=h id=h value=?php echo $k; ? /

Y llamas a la imagen como:

img src=as_img.php?k=?php echo $k; ?  /

Por último, una vez se a enviado el formulario, compruebas que el valor del 
campo oculto h es igual que el escrito por el usuario en el formulario.

Para más seguridad se podrían haber usado variables de sesión para guardar y 
pasar los valores de h, pero eso ya te lo dejo a ti.

Saludos,

Julio Barroso

Ricardo Ríos [EMAIL PROTECTED] escribió en el mensaje 
news:[EMAIL PROTECTED]
| Hola amigos listeros alguien conoce algun codigo libre de un captcha en 
php
| , gracias por sus comentarios.
| 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php