Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/08/2010, 13:28
dezagus
 
Fecha de Ingreso: abril-2010
Ubicación: Ping: BSAS - Arg
Mensajes: 791
Antigüedad: 14 años
Puntos: 25
Problema con Sesión

Hola a Todos.
Estoy pasando mi host a HostGator, y hablé y hablé con los técnicos sobre un Capcha que anda mal, y lo que encontré es que los errores que aparecian eran por una mal estructuración de la seción.

El Código de Captcha es:

Código PHP:
###########################################################################################
    #
    #  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); 
El tema es que este código en windows funcionó perfecto, pero desde que me pasé a hostgator (linux) comensó a tirar miles de errores.

Los técnicos me indicaron que poniendo un cierre de sesión iva a funcionar, y fue así.
Pero el problema surje que me rebota y no compara correctamente el formulario con el captcha (antes si andaba todo bien).

Donde tiene que cerrar sesión? Hay algo mal en el código que lo puede hacer incompatible con linux? (Fuera del cierre de sesión obligado).