Foros del Web » Programando para Internet » PHP »

CAPTCHA capturar variables.

Estas en el tema de CAPTCHA capturar variables. en el foro de PHP en Foros del Web. Hola a tod@s, Tengo problemas al capturar las variables del siguiente codigo: - letra2,3,4 como van fijas si que coinciden con la imagen. - En ...
  #1 (permalink)  
Antiguo 22/02/2007, 11:08
 
Fecha de Ingreso: febrero-2007
Mensajes: 1
Antigüedad: 17 años, 2 meses
Puntos: 0
Exclamación CAPTCHA capturar variables.

Hola a tod@s,

Tengo problemas al capturar las variables del siguiente codigo:

- letra2,3,4 como van fijas si que coinciden con la imagen.
- En cambio letra1 (se utiliza el random y no coincide con la que se escribe en prueba.txt)

Me gustaria generar un codigo aletorio del captcha, almacenarlo en una variable y usarla posteriormente para verificar.

<?php

// Juego de letras para usar
$letras = "123456789";

$dado = rand (0,8);

$letra1 = $letras[$dado];
$letra2 = "2";
$letra3 = "3";
$letra4 = "4";


$myFile = "prueba.txt";
$fh = fopen($myFile, 'w+') or die("Error!!");
fwrite($fh, "$letra1");
fwrite($fh, "$letra2");
fwrite($fh, "$letra3");
fwrite($fh, "$letra4");
fwrite($fh, "\n$dado");
fclose($fh);

// Configuración tamaño imagen y tamaño fuente
$ancho_caja = 150;
$alto_caja = 50;
$tam_letra = 10;
$tam_letra_grande = 30;
// angulo máximo que rota (izq y der) cada letra
$angmax = 20;
// Establecer el tipo de contenido
header("Content-type: image/png");

// Creamos una imagen
$im = imagecreate($ancho_caja, $alto_caja);

// Creo el color del texto, del texto del fondo y del fondo de la imagen
$gris = ImageColorAllocate($im, 255, 102, 0);
$colorLetra = ImageColorAllocate($im, 255, 255, 102);
$colorLetraFondo = ImageColorAllocate($im, 255, 204, 51);


// tipo de letra obtenido en dafont.net
$fuente = './Hotel Coral Essex.ttf';

// Calculo el número de líneas que entran
$caja_texto = imagettfbbox($tam_letra, 0, $fuente , $letras);
$alto_linea = abs($caja_texto[7]-$caja_texto[1]);
$num_lineas = intval($alto_caja / $alto_linea)+1;

// Dibujo las letras del fondo
// Cada letra de escribe de una en una para poder
// darle una rotación independiente al resto
$pos = 0;
for ($i = 0; $i<$num_lineas; $i++) {
$x = 0;
for ($j = 0; $j<30; $j++) {
$texto_linea = $letras[rand(0, strlen($letras)-1)].' ';
$caja_texto = imagettfbbox($tam_letra, 0, $fuente , $texto_linea);
imagettftext($im, $tam_letra, rand(-$angmax, $angmax), $x, $alto_linea*$i, $colorLetraFondo, $fuente , $texto_linea);
// Posicion x de la siguiente letra
$x += $caja_texto[2] - $caja_texto[0];
}
}

// Escribo las cuatro letras del CAPTCHA

$ang1 = rand(-$angmax, $angmax);
$caja_texto = imagettfbbox($tam_letra_grande, $ang1, $fuente , $letra1);
$y1 = abs($caja_texto[7]-$caja_texto[1]);
$x1 = abs($caja_texto[2]-$caja_texto[0]);

$ang2 = rand(-$angmax, $angmax);
$caja_texto = imagettfbbox($tam_letra_grande, $ang2, $fuente , $letra2);
$y2 = abs($caja_texto[7]-$caja_texto[1]);
$x2 = abs($caja_texto[2]-$caja_texto[0]);

$ang3 = rand(-$angmax, $angmax);
$caja_texto = imagettfbbox($tam_letra_grande, $ang3, $fuente , $letra3);
$y3 = abs($caja_texto[7]-$caja_texto[1]);
$x3 = abs($caja_texto[2]-$caja_texto[0]);

$ang4 = rand(-$angmax, $angmax);
$caja_texto = imagettfbbox($tam_letra_grande, $ang4, $fuente , $letra4);
$y4 = abs($caja_texto[7]-$caja_texto[1]);
$x4 = abs($caja_texto[2]-$caja_texto[0]);

imagettftext($im, $tam_letra_grande, $ang1, ($ancho_caja/2)-(($x1+$x2+$x3+$x4)/2), $y1+($alto_caja-$y1)/2, $colorLetra, $fuente , $letra1);
imagettftext($im, $tam_letra_grande, $ang2, ($ancho_caja/2)-(($x1+$x2+$x3+$x4)/2)+($x1), $y2+($alto_caja-$y2)/2, $colorLetra, $fuente , $letra2);
imagettftext($im, $tam_letra_grande, $ang3, ($ancho_caja/2)-(($x1+$x2+$x3+$x4)/2)+($x1+$x2), $y3+($alto_caja-$y3)/2, $colorLetra, $fuente , $letra3);
imagettftext($im, $tam_letra_grande, $ang4, ($ancho_caja/2)-(($x1+$x2+$x3+$x4)/2)+($x1+$x2+$x3), $y4+($alto_caja-$y4)/2, $colorLetra, $fuente , $letra4);

imagepng($im);
imagedestroy($im);


?>

Gracias por adelantado
  #2 (permalink)  
Antiguo 22/02/2007, 11:12
Avatar de ebe
ebe
 
Fecha de Ingreso: marzo-2004
Ubicación: Guatemala
Mensajes: 363
Antigüedad: 20 años, 1 mes
Puntos: 11
Re: CAPTCHA capturar variables.

Te recomiendo esta clase.

http://www.sitepoint.com/article/tou...security-image

un saludo.
__________________
http://dev.wsnetcorp.com
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:39.