Foros del Web » Programando para Internet » PHP »

Problema con Capcha en HostGator

Estas en el tema de Problema con Capcha en HostGator en el foro de PHP en Foros del Web. Hola Amigo, estoy mudando mi host local a la web. Ya gracias a ustedes y a los tutoriales pude pasar todo a mysql y funciona ...
  #1 (permalink)  
Antiguo 11/08/2010, 09:35
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Problema con Capcha en HostGator

Hola Amigo, estoy mudando mi host local a la web.
Ya gracias a ustedes y a los tutoriales pude pasar todo a mysql y funciona perfectamente.

Me faltan pequeños detalles, probar todo y les pasaré la web una ves finalizada.

Les comento, tengo un problema con el Capcha desde que mudé la web
a HostGator, el error Completo dice esto al ejecutar el php que genera la imagen:

Cita:
Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/miweb/public_html/captcha/captcha.php on line 64

Warning: imagettftext() expects parameter 1 to be resource, string given in /home/miweb/public_html/captcha/captcha.php on line 64

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/miweb/public_html/captcha/captcha.php on line 64

Warning: imagettftext() expects parameter 1 to be resource, string given in /home/miweb/public_html/captcha/captcha.php on line 64

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/miweb/public_html/captcha/captcha.php on line 64

Warning: imagettftext() expects parameter 1 to be resource, string given in /home/miweb/public_html/captcha/captcha.php on line 64

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/miweb/public_html/captcha/captcha.php on line 64

Warning: imagettftext() expects parameter 1 to be resource, string given in /home/miweb/public_html/captcha/captcha.php on line 64

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/miweb/public_html/captcha/captcha.php on line 64

Warning: imagettftext() expects parameter 1 to be resource, string given in /home/miweb/public_html/captcha/captcha.php on line 64

Warning: imageconvolution() expects parameter 1 to be resource, string given in /home/miweb/public_html/captcha/captcha.php on line 74

Warning: Cannot modify header information - headers already sent by (output started at /home/miweb/public_html/captcha/captcha.php:64) in /home/miweb/public_html/captcha/captcha.php on line 77

Warning: Cannot modify header information - headers already sent by (output started at /home/miweb/public_html/captcha/captcha.php:64) in /home/miweb/public_html/captcha/captcha.php on line 78

Warning: Cannot modify header information - headers already sent by (output started at /home/miweb/public_html/captcha/captcha.php:64) in /home/miweb/public_html/captcha/captcha.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/miweb/public_html/captcha/captcha.php:64) in /home/miweb/public_html/captcha/captcha.php on line 82

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/miweb/public_html/captcha/captcha.php on line 83

Uno de los Errores que destaco es:


Cita:
Warning: Cannot modify header information - headers already sent by (output started at /home/miweb/public_html/captcha/captcha.php:64) in /home/miweb/public_html/captcha/captcha.php on line 77

Warning: Cannot modify header information - headers already sent by (output started at /home/miweb/public_html/captcha/captcha.php:64) in /home/miweb/public_html/captcha/captcha.php on line 78

Warning: Cannot modify header information - headers already sent by (output started at /home/miweb/public_html/captcha/captcha.php:64) in /home/miweb/public_html/captcha/captcha.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/miweb/public_html/captcha/captcha.php:64) in /home/miweb/public_html/captcha/captcha.php on line 82

Por lo que tengo entendido, no puede cambiar la información del Head.
Esté es el codigo completo para el que lo quiera usar:


Código PHP:
    #create image and set background color
    
$captcha imagecreatetruecolor(120,35);
    
$background_color imagecolorallocate($captcha255255255);
    
imagefill($captcha00$background_color);
    
    
#generate a random string of 5 characters
    
$string substr(md5(rand()*time()),0,5);

    
#make string uppercase and replace "O" and "0" to avoid mistakes
    
$string strtoupper($string);
    
$string str_replace("O","B"$string);
    
$string str_replace("0","C"$string);

    
#save string in session "captcha" key
    
session_start();
    
$_SESSION["captcha"]=$string;

    
#place each character in a random position
    
$font 'arial.ttf';
    for(
$i=0;$i<5;$i++){
        
$color rand(0,32);
        if(
file_exists($font)){
            
$x=4+$i*23+rand(0,6);
            
$y=rand(18,28);
            
imagettftext  ($captcha15rand(-25,25), $x$yimagecolorallocate($captcha$color$color$color), $font$string[$i]);
        }else{
            
$x=5+$i*24+rand(0,6);
            
$y=rand(1,18);
            
imagestring($captcha5$x$y$string[$i], imagecolorallocate($captcha$color$color$color));
        }
    }
    
    
#applies distorsion to image
    
$matrix = array(array(111), array(1.071.0), array(111));
    
imageconvolution($captcha$matrix1632);

    
#avoids catching
    
header("Expires: 0");
    
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    
header("Cache-Control: private",false); 

    
#return the image
    
header("Content-type: image/gif");
    
imagejpeg($captcha); 
Y esta es la sección que modifica el head:

Código PHP:
    #avoids catching
    
header("Expires: 0");
    
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    
header("Cache-Control: private",false); 

    
#return the image
    
header("Content-type: image/gif");
    
imagejpeg($captcha); 

Veo veo y veo el código y no entiendo cual es el problema, alguien me podria explicar porfavor?

Gracias.
  #2 (permalink)  
Antiguo 11/08/2010, 10:16
 
Fecha de Ingreso: junio-2009
Mensajes: 128
Antigüedad: 14 años, 10 meses
Puntos: 5
Respuesta: Problema con Capcha en HostGator

Buen día amigo,

Al inicio de tu ?PHP agrega:


ob_start();


y al final antes del tag de cierre escribe,

ob_end_flush();
?>

Cual es exactamente la línea 64?

Saludos
__________________
krowmx
Hostings y Dominios
Tú defines la idea, nosotros la desarrollamos
  #3 (permalink)  
Antiguo 11/08/2010, 10:49
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Respuesta: Problema con Capcha en HostGator

La linea 64 dice esto:

#place each character in a random position
$font = 'arial.ttf';
for($i=0;$i<5;$i++){
$color = rand(0,32);
if(file_exists($font)){
$x=4+$i*23+rand(0,6);
$y=rand(18,28);
imagettftext ($captcha, 15, rand(-25,25), $x, $y, imagecolorallocate($captcha, $color, $color, $color), $font, $string[$i]);
}else{
$x=5+$i*24+rand(0,6);
$y=rand(1,18);
imagestring($captcha, 5, $x, $y, $string[$i], imagecolorallocate($captcha, $color, $color, $color));
}
}
  #4 (permalink)  
Antiguo 11/08/2010, 10:52
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Respuesta: Problema con Capcha en HostGator

No Funcionó, alguna idea?

Código PHP:
<?php 

ob_start
();


    
###########################################################################################
    #
    #  CAPTCHA FÁCIL 1.0
    #
    #  Autor: Alejandro Martín Núñez
    #  Contact: alemnunez at gmail dot com
    #  Date: October 10, 2009
    #
    #  COMO USAR CAPTCHA FÁCIL
    #
    #  FORMULARIO
    #  En el formulario que deseas validar, inserta el siguiente código:
    #  
    #  <img src="captcha.php" /><br/>
    #  <input type="text" size="12" name="captcha" />
    #
    #
    #  VERIFICACIÓN
    #  Al procesar el formulario, compara el contenido del campo que 
    #  completó el usuario con el contenido de $_SESSION["captcha"] 
    #  que generó este programa:
    #
    #  session_start();
    #  if(strtoupper($_REQUEST["captcha"]) == $_SESSION["captcha"]){
    #     // REMPLAZO EL CAPTCHA USADO POR UN TEXTO LARGO PARA EVITAR QUE SE VUELVA A INTENTAR
    #     $_SESSION["captcha"] = md5(rand()*time());
    #      // INSERTA EL CÓDIGO EXITOSO AQUI
    #  }else{
    #     // REMPLAZO EL CAPTCHA USADO POR UN TEXTO LARGO PARA EVITAR QUE SE VUELVA A INTENTAR
    #     $_SESSION["captcha"] = md5(rand()*time());
    #      // INSERTA EL CÓDIGO DE ERROR AQUÍ
    #  }
    #
    #  
    #  OLVIDÁ EL SPAM!
    #
    ###########################################################################################
    
    #create image and set background color
    
$captcha imagecreatetruecolor(120,35);
    
$background_color imagecolorallocate($captcha255255255);
    
imagefill($captcha00$background_color);
    
    
#generate a random string of 5 characters
    
$string substr(md5(rand()*time()),0,5);

    
#make string uppercase and replace "O" and "0" to avoid mistakes
    
$string strtoupper($string);
    
$string str_replace("O","B"$string);
    
$string str_replace("0","C"$string);

    
#save string in session "captcha" key
    
session_start();
    
$_SESSION["captcha"]=$string;

    
#place each character in a random position
    
$font 'arial.ttf';
    for(
$i=0;$i<5;$i++){
        
$color rand(0,32);
        if(
file_exists($font)){
            
$x=4+$i*23+rand(0,6);
            
$y=rand(18,28);
            
imagettftext  ($captcha15rand(-25,25), $x$yimagecolorallocate($captcha$color$color$color), $font$string[$i]);
        }else{
            
$x=5+$i*24+rand(0,6);
            
$y=rand(1,18);
            
imagestring($captcha5$x$y$string[$i], imagecolorallocate($captcha$color$color$color));
        }
    }
    
    
#applies distorsion to image
    
$matrix = array(array(111), array(1.071.0), array(111));
    
imageconvolution($captcha$matrix1632);

    
#avoids catching
    
header("Expires: 0");
    
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    
header("Cache-Control: private",false); 

    
#return the image
    
header("Content-type: image/gif");
    
imagejpeg($captcha);
    
    
ob_end_flush(); 
    
?>
Lo convirtio en Texto al Error:

Cita:
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/miweb/public_html/captcha/captcha.php</b> on line <b>68</b><br />
<br />
<b>Warning</b>: imagettftext() expects parameter 1 to be resource, string given in <b>/home/miweb/public_html/captcha/captcha.php</b> on line <b>68</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/miweb/public_html/captcha/captcha.php</b> on line <b>68</b><br />
<br />
<b>Warning</b>: imagettftext() expects parameter 1 to be resource, string given in <b>/home/miweb/public_html/captcha/captcha.php</b> on line <b>68</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/miweb/public_html/captcha/captcha.php</b> on line <b>68</b><br />
<br />
<b>Warning</b>: imagettftext() expects parameter 1 to be resource, string given in <b>/home/miweb/public_html/captcha/captcha.php</b> on line <b>68</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/miweb/public_html/captcha/captcha.php</b> on line <b>68</b><br />
<br />
<b>Warning</b>: imagettftext() expects parameter 1 to be resource, string given in <b>/home/miweb/public_html/captcha/captcha.php</b> on line <b>68</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/miweb/public_html/captcha/captcha.php</b> on line <b>68</b><br />
<br />
<b>Warning</b>: imagettftext() expects parameter 1 to be resource, string given in <b>/home/miweb/public_html/captcha/captcha.php</b> on line <b>68</b><br />
<br />
<b>Warning</b>: imageconvolution() expects parameter 1 to be resource, string given in <b>/home/miweb/public_html/captcha/captcha.php</b> on line <b>78</b><br />
<br />
<b>Warning</b>: imagejpeg(): supplied argument is not a valid Image resource in <b>/home/miweb/public_html/captcha/captcha.php</b> on line <b>87</b><br />
  #5 (permalink)  
Antiguo 11/08/2010, 10:57
 
Fecha de Ingreso: junio-2009
Mensajes: 128
Antigüedad: 14 años, 10 meses
Puntos: 5
Respuesta: Problema con Capcha en HostGator

Es decir solo quedó el error de la line 68,78,87, se eliminó el 64?

Saludos
__________________
krowmx
Hostings y Dominios
Tú defines la idea, nosotros la desarrollamos
  #6 (permalink)  
Antiguo 11/08/2010, 11:00
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Respuesta: Problema con Capcha en HostGator

Exacto, planché el error completo.
Desaparecio el 64 y otros más.
  #7 (permalink)  
Antiguo 11/08/2010, 11:09
 
Fecha de Ingreso: junio-2009
Mensajes: 128
Antigüedad: 14 años, 10 meses
Puntos: 5
Respuesta: Problema con Capcha en HostGator

Bueno ahi te marca que esos errores es por que no estas enviando una imagen válida, como está tu HTML? es decir el FORM

Saludos
__________________
krowmx
Hostings y Dominios
Tú defines la idea, nosotros la desarrollamos
  #8 (permalink)  
Antiguo 11/08/2010, 11:14
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Respuesta: Problema con Capcha en HostGator

Ahhh...

El script que toma el php es así:

Cita:
<table width="158" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><div align="center"><img src="captcha/captcha.php" /></div></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><div align="center">
<input type="text" size="16" name="captcha" style="height:15px;color:grey" />
</div></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><div align="center">
<input name="submit" type="submit" id="Enviar" value="Enviar" />
</div></td>
</tr>
</table>

Y el formulario está así:

<form id="form1" name="form1" method="post" action="new.php">


Gracias KrowMx desde ya por la predisposición.
  #9 (permalink)  
Antiguo 11/08/2010, 11:23
 
Fecha de Ingreso: junio-2009
Mensajes: 128
Antigüedad: 14 años, 10 meses
Puntos: 5
Respuesta: Problema con Capcha en HostGator

1.-Muy bien amigo, entonces estoy comprendiendo un poco más, el captcha.php es en donde esta el código de error?, es decir ni siquiera te aparece el captcha en el formulario vdd?

2.- Ó el problema persiste al hacer clic en enviar?

Saludos
__________________
krowmx
Hostings y Dominios
Tú defines la idea, nosotros la desarrollamos
  #10 (permalink)  
Antiguo 11/08/2010, 11:28
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Respuesta: Problema con Capcha en HostGator

Cita:
Iniciado por KrowMx Ver Mensaje
1.-Muy bien amigo, entonces estoy comprendiendo un poco más, el captcha.php es en donde esta el código de error?, es decir ni siquiera te aparece el captcha en el formulario vdd?

2.- Ó el problema persiste al hacer clic en enviar?

Saludos
Exacto, aparece el clásico fondo blanco con la X Roja, este codigo funciona, lo probé en el apache de mi pc cientas de veces, eso es lo más raro.

En la web (Formulario) solamente hay una sesión y nada más (si mal no recuerdo).

Cuando abro capcha.php de localhost, anda exelente.
Cuando abro capcha.php de hostgator, salen los errores que puse arriva.

Rarisimo.
  #11 (permalink)  
Antiguo 11/08/2010, 11:45
 
Fecha de Ingreso: junio-2009
Mensajes: 128
Antigüedad: 14 años, 10 meses
Puntos: 5
Respuesta: Problema con Capcha en HostGator

Muy bien amigo, pensaba que no funcionaba en gral, los errores aqui marcados se deben a que hostgator necesitas darle permisos especiales a la carpeta del captcha así como tener instalados la librerias GD

generalmente con poner permisos 755 debería funcionar a tu carpeta del captcha.
no es ningún error de programación 100% seguro es la configuración en hostgator, a mi me ha sucedido problemas de ese tipo tmb con ellos y hablando con el soporte técnico me han dado esa solución, verifica los permisos con ellos y las librerias GD

Saludos!!
__________________
krowmx
Hostings y Dominios
Tú defines la idea, nosotros la desarrollamos
  #12 (permalink)  
Antiguo 11/08/2010, 13:28
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Respuesta: Problema con Capcha en HostGator

Te comento :D
estuve provando, y apretando muchas veces f5 hasta que apareciera.

Tuve un momento en que aparecio. Y despues de bo... cambie un permiso que me olvide cual era y desaparecio.

Lo que si me sale mucho el error 500 al asignar 777 o algo superior a 755.
¿Que permisos le asigno entonces?
Solo ejecución?


(Las Librerias GD según hostgator están instaladas)


Gracias KrowMx nuevaemente, ya casi lo tengo.
  #13 (permalink)  
Antiguo 11/08/2010, 13:40
 
Fecha de Ingreso: junio-2009
Mensajes: 128
Antigüedad: 14 años, 10 meses
Puntos: 5
Respuesta: Problema con Capcha en HostGator

Amigo, deberias preguntar en el CHAT LIVE de hostgator, así fue como yo solucioné mi error, ahora mismo ya no tengo a la mano los permisos que se requieren para ejectuar este tipo de scripts,

Prueba con 750/755, pero mejor busca en hostgator.com
__________________
krowmx
Hostings y Dominios
Tú defines la idea, nosotros la desarrollamos
  #14 (permalink)  
Antiguo 11/08/2010, 15:08
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Respuesta: Problema con Capcha en HostGator

Solucionado master, al parecer el problema estaba en el htacceses que no me dejaba, ise un subdominio ya que estaba y todo se arregló.

Mil Gracias.

Etiquetas: hostgator, captcha
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 11:36.