Foros del Web » Programando para Internet » PHP »

CAPTCHA del dreamweaver (es PHP!)

Estas en el tema de CAPTCHA del dreamweaver (es PHP!) en el foro de PHP en Foros del Web. He instalado la extension en DW para configurar el CAPTCHA muy cómodamente, pero no funcina y no puedo darme cuenta donde está el error. El ...
  #1 (permalink)  
Antiguo 18/10/2006, 21:01
 
Fecha de Ingreso: marzo-2005
Mensajes: 201
Antigüedad: 19 años, 1 mes
Puntos: 0
CAPTCHA del dreamweaver (es PHP!)

He instalado la extension en DW para configurar el CAPTCHA muy cómodamente, pero no funcina y no puedo darme cuenta donde está el error. El problema es que no identifica si el codigo es correcto o no, sino que ejecuta el formulario sin considerar el ingreso de codigo. Si alguien puede darse cuenta dónde está el problema, agradezco mucho su respuesta:

Código PHP:
<?php
session_start
();
if(isset(
$_POST["textfield"])) {
    if((
$_SESSION['captcha_code'] == $_POST['textfield']) && (!empty($_SESSION['captcha_code'])) ) {
        
//Passed!
        
$captcha_msg="Thank you";
    }else{
        
// Not passed 8-(
        
$captcha_msg="invalid_code";
        if(isset(
$_POST["MM_insert"])){
              unset(
$_POST["MM_insert"]);
        }
        if(isset(
$_POST["MM_update"])){
            unset(
$_POST["MM_update"]);
        }
    }
}
class 
CaptchaImage {
    var 
$font "verdana.ttf";
    function 
hex_to_dec($hexcolor){
    
//convert hex hex values to decimal ones
    
$dec_color=array('r'=>hexdec(substr($hexcolor,0,2)),'g'=>hexdec(substr($hexcolor,2,2)),'b'=>hexdec(substr($hexcolor,4,2)));
    return 
$dec_color;
    }
    function 
generateCode($characters) {
        
/* list all possible characters, similar looking characters and vowels have been removed */
        
$possible '23456789bcdfghjkmnpqrstvwxyz'
        
$code '';
        
$i 0;
        while (
$i $characters) { 
            
$code .= substr($possiblemt_rand(0strlen($possible)-1), 1);
            
$i++;
        }
        return 
$code;
    }
    function 
CaptchaImage($width='120',$height='30',$characters='6',$hex_bg_color='FFFFFF',$hex_text_color="FF0000",$hex_noise_color="CC0000"$img_file='captcha.jpg') {
        
$rgb_bg_color=$this->hex_to_dec($hex_bg_color);
        
$rgb_text_color=$this->hex_to_dec($hex_text_color);
        
$rgb_noise_color=$this->hex_to_dec($hex_noise_color);
        
$code $this->generateCode($characters);
        
/* font size will be 60% of the image height */
        
$font_size $height 0.60;
        
$image = @imagecreate($width$height) or die('Cannot Initialize new GD image stream');
        
/* set the colours */
        
$background_color imagecolorallocate($image$rgb_bg_color['r'], $rgb_bg_color['g'],$rgb_bg_color['b']);
        
$text_color imagecolorallocate($image$rgb_text_color['r'], $rgb_text_color['g'],$rgb_text_color['b']);
        
$noise_color imagecolorallocate($image$rgb_noise_color['r'], $rgb_noise_color['g'],$rgb_noise_color['b']);
        
/* generate random dots in background */
        
for( $i=0$i<($width*$height)/3$i++ ) {
            
imagefilledellipse($imagemt_rand(0,$width), mt_rand(0,$height), 11$noise_color);
        }
        
/* generate random lines in background */
        
for( $i=0$i<($width*$height)/150$i++ ) {
            
imageline($imagemt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
        }
        
/* create textbox and add text */
        
$textbox imagettfbbox($font_size0$this->font$code);
        
$x = ($width $textbox[4])/2;
        
$y = ($height $textbox[5])/2;
        
imagettftext($image$font_size0$x$y$text_color$this->font $code);
        
/* save the image */
        
imagejpeg($image,$img_file);
        
imagedestroy($image);
        echo 
"<img src=\"$img_file\" width=\"$width\" height=\"$height\" alt=\"security code\" id=\"captchaImg\">";
        
$_SESSION['captcha_code'] = $code;
    }

}
?><form id="form1" name="form1" method="post" action="siguiente.php">
<table width="600" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>jjjj
      <input type="text" name="textfield" />
      <?php $captcha = new CaptchaImage(120,50,5,'FFFFFF','000000','000000');?><input type="submit" name="Submit" value="Enviar" /></td>
  </tr>
</table>

</form>
  #2 (permalink)  
Antiguo 19/10/2006, 05:30
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Se "supone" que el código que genere esa "extensión" de DW debe estar más que comprobado.

Ahora .. lo que si te puedo indicar es que ese código usa sesiones para parte de su proceso. Sobre todo para la validación del código pues .. al generar el código se crea una variable de sesión y luego se valida contra la que desde el formulario HTML ingresas.

Lo más probable es que tengsa problemas con las sesiones .. que no se esté propagando el SID y en consecuencia no puedes acceder a los datos de la sesión creada anteriormente.

Ves haciendo comprobaciones:
Despues de session_start() .. vé que valor tiene: $_SESSION['captcha_code']

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
  #3 (permalink)  
Antiguo 19/10/2006, 08:20
 
Fecha de Ingreso: marzo-2005
Mensajes: 201
Antigüedad: 19 años, 1 mes
Puntos: 0
¿Como envio las variables?

Por lo que veo ahora, debería suceder algo luego del segundo "if" (en la linea 4), es decir, debería allí enviar el email con los datos ingresados. ¿Cómo debo hacer eso? Porque antes lo tenía en el "action" del formulario, que dirigia al php que enviaba los datos, pero ahora el action refiere al mismo archivo.

Código PHP:
<?php
session_start
();
if(isset(
$_POST["textfield"])) {
    if((
$_SESSION['captcha_code'] == $_POST['textfield']) && (!empty($_SESSION['captcha_code'])) ) {
        
//Passed!
        
$captcha_msg="Thank you";
        
    <
script language="JavaScript">
function 
cerrar() {
var 
ventana window.self;
ventana.opener window.self;
parent.close();
}
</script>

Muchas gracias.
<body OnLoad='setTimeout("cerrar();",2000)'>

<?
    
}else{
        
// Not passed 8-(
        
$captcha_msg="invalid_code";
        if(isset(
$_POST["MM_insert"])){
              unset(
$_POST["MM_insert"]);
        }
        if(isset(
$_POST["MM_update"])){
            unset(
$_POST["MM_update"]);
        }
    }
}
class 
CaptchaImage {
    var 
$font "verdana.ttf";
    function 
hex_to_dec($hexcolor){
    
//convert hex hex values to decimal ones
    
$dec_color=array('r'=>hexdec(substr($hexcolor,0,2)),'g'=>hexdec(substr($hexcolor,2,2)),'b'=>hexdec(substr($hexcolor,4,2)));
    return 
$dec_color;
    }
    function 
generateCode($characters) {
        
/* list all possible characters, similar looking characters and vowels have been removed */
        
$possible '23456789bcdfghjkmnpqrstvwxyz'
        
$code '';
        
$i 0;
        while (
$i $characters) { 
            
$code .= substr($possiblemt_rand(0strlen($possible)-1), 1);
            
$i++;
        }
        return 
$code;
    }
    function 
CaptchaImage($width='120',$height='30',$characters='6',$hex_bg_color='FFFFFF',$hex_text_color="FF0000",$hex_noise_color="CC0000"$img_file='captcha.jpg') {
        
$rgb_bg_color=$this->hex_to_dec($hex_bg_color);
        
$rgb_text_color=$this->hex_to_dec($hex_text_color);
        
$rgb_noise_color=$this->hex_to_dec($hex_noise_color);
        
$code $this->generateCode($characters);
        
/* font size will be 60% of the image height */
        
$font_size $height 0.60;
        
$image = @imagecreate($width$height) or die('Cannot Initialize new GD image stream');
        
/* set the colours */
        
$background_color imagecolorallocate($image$rgb_bg_color['r'], $rgb_bg_color['g'],$rgb_bg_color['b']);
        
$text_color imagecolorallocate($image$rgb_text_color['r'], $rgb_text_color['g'],$rgb_text_color['b']);
        
$noise_color imagecolorallocate($image$rgb_noise_color['r'], $rgb_noise_color['g'],$rgb_noise_color['b']);
        
/* generate random dots in background */
        
for( $i=0$i<($width*$height)/3$i++ ) {
            
imagefilledellipse($imagemt_rand(0,$width), mt_rand(0,$height), 11$noise_color);
        }
        
/* generate random lines in background */
        
for( $i=0$i<($width*$height)/150$i++ ) {
            
imageline($imagemt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
        }
        
/* create textbox and add text */
        
$textbox imagettfbbox($font_size0$this->font$code);
        
$x = ($width $textbox[4])/2;
        
$y = ($height $textbox[5])/2;
        
imagettftext($image$font_size0$x$y$text_color$this->font $code);
        
/* save the image */
        
imagejpeg($image,$img_file);
        
imagedestroy($image);
        echo 
"<img src=\"$img_file\" width=\"$width\" height=\"$height\" alt=\"security code\" id=\"captchaImg\">";
        
$_SESSION['captcha_code'] = $code;
    }

}
?><form id="form1" name="form1" method="post" action="formch2CAP.php">
<table width="600" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>jjjj
      <input type="text" name="textfield" />
      <?php $captcha = new CaptchaImage(60,50,2,'ffffff','990000','990000');?><input type="submit" name="Submit" value="Enviar" /></td>
  </tr>
</table>

</form>
  #4 (permalink)  
Antiguo 19/10/2006, 08:22
 
Fecha de Ingreso: marzo-2005
Mensajes: 201
Antigüedad: 19 años, 1 mes
Puntos: 0
Perdon, el script que vale es este:

Código PHP:
<?php
session_start
();
if(isset(
$_POST["textfield"])) {
    if((
$_SESSION['captcha_code'] == $_POST['textfield']) && (!empty($_SESSION['captcha_code'])) ) {
        
//Passed!
        
$captcha_msg="Thank you";
        echo 
'gracias por sus datos'//AQUI DEBERIA ENVIAR LOS DATOS... ¿COMO?

<?
    }else{
        
// Not passed 8-(
        
$captcha_msg="invalid_code";
        if(isset(
$_POST["MM_insert"])){
              unset(
$_POST["MM_insert"]);
        }
        if(isset(
$_POST["MM_update"])){
            unset(
$_POST["MM_update"]);
        }
    }
}
class 
CaptchaImage {
    var 
$font "verdana.ttf";
    function 
hex_to_dec($hexcolor){
    
//convert hex hex values to decimal ones
    
$dec_color=array('r'=>hexdec(substr($hexcolor,0,2)),'g'=>hexdec(substr($hexcolor,2,2)),'b'=>hexdec(substr($hexcolor,4,2)));
    return 
$dec_color;
    }
    function 
generateCode($characters) {
        
/* list all possible characters, similar looking characters and vowels have been removed */
        
$possible '23456789bcdfghjkmnpqrstvwxyz'
        
$code '';
        
$i 0;
        while (
$i $characters) { 
            
$code .= substr($possiblemt_rand(0strlen($possible)-1), 1);
            
$i++;
        }
        return 
$code;
    }
    function 
CaptchaImage($width='120',$height='30',$characters='6',$hex_bg_color='FFFFFF',$hex_text_color="FF0000",$hex_noise_color="CC0000"$img_file='captcha.jpg') {
        
$rgb_bg_color=$this->hex_to_dec($hex_bg_color);
        
$rgb_text_color=$this->hex_to_dec($hex_text_color);
        
$rgb_noise_color=$this->hex_to_dec($hex_noise_color);
        
$code $this->generateCode($characters);
        
/* font size will be 60% of the image height */
        
$font_size $height 0.60;
        
$image = @imagecreate($width$height) or die('Cannot Initialize new GD image stream');
        
/* set the colours */
        
$background_color imagecolorallocate($image$rgb_bg_color['r'], $rgb_bg_color['g'],$rgb_bg_color['b']);
        
$text_color imagecolorallocate($image$rgb_text_color['r'], $rgb_text_color['g'],$rgb_text_color['b']);
        
$noise_color imagecolorallocate($image$rgb_noise_color['r'], $rgb_noise_color['g'],$rgb_noise_color['b']);
        
/* generate random dots in background */
        
for( $i=0$i<($width*$height)/3$i++ ) {
            
imagefilledellipse($imagemt_rand(0,$width), mt_rand(0,$height), 11$noise_color);
        }
        
/* generate random lines in background */
        
for( $i=0$i<($width*$height)/150$i++ ) {
            
imageline($imagemt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
        }
        
/* create textbox and add text */
        
$textbox imagettfbbox($font_size0$this->font$code);
        
$x = ($width $textbox[4])/2;
        
$y = ($height $textbox[5])/2;
        
imagettftext($image$font_size0$x$y$text_color$this->font $code);
        
/* save the image */
        
imagejpeg($image,$img_file);
        
imagedestroy($image);
        echo 
"<img src=\"$img_file\" width=\"$width\" height=\"$height\" alt=\"security code\" id=\"captchaImg\">";
        
$_SESSION['captcha_code'] = $code;
    }

}
?><form id="form1" name="form1" method="post" action="formch2CAP.php">
<table width="600" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>jjjj
      <input type="text" name="textfield" />
      <?php $captcha = new CaptchaImage(60,50,2,'ffffff','990000','990000');?><input type="submit" name="Submit" value="Enviar" /></td>
  </tr>
</table>

</form>

Última edición por Cluster; 19/10/2006 a las 08:29
  #5 (permalink)  
Antiguo 19/10/2006, 09:39
 
Fecha de Ingreso: marzo-2005
Mensajes: 201
Antigüedad: 19 años, 1 mes
Puntos: 0
Extension CAPTCHA para Dreamweaver

Se puede bajar desde aqui:

http://www.dwug.es/go/344
  #6 (permalink)  
Antiguo 21/10/2006, 14:22
 
Fecha de Ingreso: marzo-2005
Mensajes: 201
Antigüedad: 19 años, 1 mes
Puntos: 0
El problema al que no le encuentro solucion es este: tengo el formulario web para que sea enviado por email. Pero resulta que la "action" que debe realizar ahora es la validacin del CAPTCHA y, de ser valida, sí enviar los datos. Entonces, ¿Como debo hacer, ahora que el "action" es de validacion y no de envío, para que leugo de validar envie el formulario?
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 20:16.