Foros del Web » Programando para Internet » PHP » Frameworks y PHP orientado a objetos »

PHP OO [Opinion] Captcha

Estas en el tema de [Opinion] Captcha en el foro de Frameworks y PHP orientado a objetos en Foros del Web. Hola a todos hace unos días realice un simple captcha en poo, solo para refrescarme sus funciones me gustaría opiniones sobre el código que mejorar, ...
  #1 (permalink)  
Antiguo 21/12/2012, 08:13
 
Fecha de Ingreso: junio-2011
Ubicación: Barcelona
Mensajes: 212
Antigüedad: 12 años, 11 meses
Puntos: 17
[Opinion] Captcha

Hola a todos hace unos días realice un simple captcha en poo, solo para refrescarme sus funciones me gustaría opiniones sobre el código que mejorar, que va mal, etc.

Código PHP:
<?php
class Captcha
{
    private 
$width;
    private 
$height;
    private 
$texto;
    private 
$imagen;
    private 
$fuente;
    private 
$color_fondo;
    private 
$color_negro;
    private 
$color_inv;
    private 
$rgb=array();
    
        public function 
__construct($width,$height)
        {
            
$this->width=$width;
            
$this->height=$height;
            
$this->imagen imagecreatetruecolor($this->width,$this->height);
        }
        
// Si no dominais el uso del imagefttext dejar el valor size_font por default.
        
public function configuracion($string,$num_caracteres,$font="monofont.ttf",$size_font=20)
        {
            
$this->color_fondo=$color_fondo;
            
$this->color_negro=$color_negro;
            
$this->fuente=$fuente;
            
$this->rgb[0]=mt_rand(0,255);
            
$this->rgb[1]=mt_rand(0,255);
            
$this->rgb[2]=mt_rand(0,255);
            
            if(
$num_caracteres 6)
            {
                echo 
"El numero maximo de caracteres es 6";
                exit();
            }
                
                
$color_fondo=imagecolorallocate($this->imagen,$this->rgb[0],$this->rgb[1],$this->rgb[2]);
                
$color_negro=imagecolorallocate($this->imagen,0,0,0);
                
            
$this->texto=$string;
            
$string substr(str_replace("O","",str_replace(0,"",strtoupper(md5(mt_rand(9999,99999))))),0,$num_caracteres);
            
imagefill($this->imagen,0,0,$color_fondo);
            
imagefttext($this->imagen,$size_font,mt_rand(-10,10),10,25,$color_negro,$font,$string);    
        }
        
        public function 
seguridad($nivel)
        {
            
$this->color_inv=$color_random;
            
$color_random=imagecolorallocate($this->imagen,255-$this->rgb[0],255-$this->rgb[1],255-$this->rgb[2]);
            switch(
$nivel)
            {
                case 
0:
                break;
                
                case 
1:
                    
imageline($this->imagen,15,0,25,$this->height,$color_random);
                    
imageline($this->imagen,30,0,5,$this->height,$color_random);
                    
imageline($this->imagen,30,0,$this->width,$this->height/2,$color_random);
                    
imageline($this->imagen,0,0,$this->width,$this->height,$color_random);
                    
imageline($this->imagen,$this->width,0,25,$this->height,$color_random);
                break;
                
                case 
2:
                    for(
$w=0;$w <= 700;$w++){
                        
$ancho_pix=mt_rand(0,$this->width);
                        
$largo_pix=mt_rand(0,$this->height);
                        
imagesetpixel($this->imagen,$ancho_pix,$largo_pix,$color_random);
                    }
                break;
                
                case 
3:
                    
imageline($this->imagen,15,0,25,$this->height,$color_random);
                    
imageline($this->imagen,30,0,5,$this->height,$color_random);
                    
imageline($this->imagen,30,0,$this->width,$this->height/2,$color_random);
                    
imageline($this->imagen,0,0,$this->width,$this->height,$color_random);
                    
imageline($this->imagen,$this->width,0,25,$this->height,$color_random);
                    for(
$w=0;$w <= 700;$w++){
                        
$ancho_pix=mt_rand(0,$this->width);
                        
$largo_pix=mt_rand(0,$this->height);
                        
imagesetpixel($this->imagen,$ancho_pix,$largo_pix,$color_random);
                    }
                break;
                
                default:
                    print(
"El nivel maximo de seguridad es 3");
                break;
            }
                
        }
        
        public function 
visualizar()
        {
            
header("Content-type: image/png");
            
imagepng($this->imagen);
            
imagedestroy($this->imagen);
        }

}
$captcha=new Captcha(80,35);
$captcha->configuracion("Hola",6); // El valor default es 5
$captcha->seguridad(3);
$captcha->visualizar();
?>
Saludos y gracias!

Etiquetas: captcha, php, poo
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 21:14.