Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/08/2008, 14:00
libso
 
Fecha de Ingreso: julio-2008
Ubicación: México
Mensajes: 61
Antigüedad: 18 años, 3 meses
Puntos: 0
Clase captcha

hola a todos :P
Bueno implementando un captcha sensillo he tenido un problema
Código PHP:
class Captcha{
    public function 
__construct(){
        
session_start(); 
        
$captcha_texto = "";
    
        for (
$i = 0; $i < 4; $i++)
            
$captcha_texto .= $this->caracter(); 
        
//session_register ();
        
$_SESSION['txt_capt'] =  $captcha_texto; 
        
        
$captcha_imagen = imagecreate(110,40);
        
$color_fondo = imagecolorallocate ($captcha_imagen, 240, 240, 240);
        
$color_letras = imagecolorallocate ($captcha_imagen, 0, 0, 0);
        
        
imagefill($captcha_imagen, 0, 0, $color_fondo);
         
        
imagechar($captcha_imagen, 4, 20, 13, $captcha_texto[0] ,$color_letras);
        
imagechar($captcha_imagen, 5, 40, 13, $captcha_texto[1] ,$color_letras);
        
imagechar($captcha_imagen, 3, 60, 13, $captcha_texto[2] ,$color_letras);
        
imagechar($captcha_imagen, 4, 80, 13, $captcha_texto[3] ,$color_letras);
                
        
header("Content-type: image/jpeg");
        
imagejpeg($captcha_imagen);
    }
    
    private function 
caracter() {
        
mt_srand((double)microtime()*1000000);
        
$valor_aleatorio = mt_rand(1,3);
        
        switch (
$valor_aleatorio) {
            case 
1:
                
$valor_aleatorio = mt_rand(97, 122); 
            break;
            case 
2:
                
$valor_aleatorio = mt_rand(48, 57);
            break;
            case 
3:
                
$valor_aleatorio = mt_rand(65, 90);
            break;
        }    
        return 
chr($valor_aleatorio);
    }
    
    public static function 
verifica ($code){
        
session_start();
        
        
$txt_capt = $_SESSION['txt_capt'];
    
        if (
$code == $txt_capt)
            return    
true;
        else
            return 
false;
            
        
session_unset();
        
session_destroy();        
    } 
esto me genera mi captcha pero como le podria hacer para que cuando haga la instancia de mi clase salga la imagen???
Código HTML:
<?
require_once 'captcha.php'; 
?>
<img src="<? new Captcha(); ?>"
<form action="verificar.php" method="post">
 <input name="code" type="text" id="texto_ingresado" size="30" />			
 <input type="submit" name="Submit" value="OK" />
</form>