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: 15 años, 9 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_imagen240240240);
        
$color_letras imagecolorallocate ($captcha_imagen000);
        
        
imagefill($captcha_imagen00$color_fondo);
         
        
imagechar($captcha_imagen42013$captcha_texto[0] ,$color_letras);
        
imagechar($captcha_imagen54013$captcha_texto[1] ,$color_letras);
        
imagechar($captcha_imagen36013$captcha_texto[2] ,$color_letras);
        
imagechar($captcha_imagen48013$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(97122); 
            break;
            case 
2:
                
$valor_aleatorio mt_rand(4857);
            break;
            case 
3:
                
$valor_aleatorio mt_rand(6590);
            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>