Foros del Web » Programando para Internet » PHP »

Clase que no funciona no se por que

Estas en el tema de Clase que no funciona no se por que en el foro de PHP en Foros del Web. hola amigos resuta que tengo una clase que me genera un php captcha pero en un hosting da todo ok chevere pero en otro host ...
  #1 (permalink)  
Antiguo 12/07/2008, 10:06
(Desactivado)
 
Fecha de Ingreso: mayo-2008
Mensajes: 67
Antigüedad: 15 años, 10 meses
Puntos: 0
Clase que no funciona no se por que

hola amigos resuta que tengo una clase que me genera un php captcha pero en un hosting da todo ok chevere pero en otro host no fucniona me vota un error ya me he roto la cabeza y no entiendo porque aqui les dejo el codigo y error que bota aver si me ayudan.

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/miweb/public_html/PHPCaptcha.lib.php on line 15
Código PHP:
<?php

/**
 * PHPcaptcha
 * @author Myokram
 * 29/03/08
 */

/**
 * Para usar esta clase:
 * Visita http://www.phperu.net/phpcaptcha
 *      
 */

class Captcha {
    
    public 
$codigo;
    private 
$refCodigos;
    private 
$refFondos;
    private 
$refFuentes;
    private 
$fuentes = array();
    private 
$refFiltro true;
    private 
$refColor = array(000);
    private 
$refTamano 25;
    private 
$refLineas true;
    private 
$refGradoDificultad 8;
    private 
$refNLineas 20;
    private 
$refCLineas false;
    private 
$refLongitud 6;
    private 
$refCaracteres = array();
    private 
$fondo;
    private 
$texto;
    private 
$ancho;
    private 
$alto;
    private 
$captcha;
    
    public function 
__construct() {
    }
    
    public function 
checkSession() {
        if(!isset(
$_SESSION)) { 
            @
session_start();
            return 
false
        }
        return 
true;
    }
    
    public function 
generaCaptcha($nuevo true) {
        
$this->checkSession();
        if(empty(
$this->codigo)) {
            if(
$nuevo == false and !empty($_SESSION['phpcaptcha_codigo'])) {
                
$this->codigo $_SESSION['phpcaptcha_codigo'];
            } else {
                
$this->generarCodigo();
            }
        }
        
$this->generarFondo();
        if(
$this->refLineas == true) {
            
$this->generarLineas();
        }
        
$this->generarTexto();
        
$this->captcha imagecreatetruecolor($this->ancho$this->alto);
        
imagecopyresampled($this->captcha$this->fondo0000$this->ancho$this->alto$this->ancho$this->alto);
        
imagecopymerge($this->captcha$this->texto0000$this->ancho$this->alto60);
        return 
true;
    }
    
    public function 
verificaCaptcha($codigo$mayus false) {
        
self::checkSession();
        
$sc = ($mayus == true) ? $_SESSION['phpcaptcha_codigo'] : strtolower($_SESSION['phpcaptcha_codigo']);
        
$vc = ($mayus == true) ? $codigo strtolower($codigo);
        if(!empty(
$sc) and $sc == $vc) {
            unset(
$_SESSION['phpcaptcha_codigo']);
            return 
true;
        }
        return 
false;
    }
    
    public function 
guardaCaptcha() {
        
$this->checkSession();
        return 
$_SESSION['phpcaptcha_codigo'] = $this->codigo;
    }
    
    public function 
muestraCaptcha() {
        
header("Expires: Sun, 1 Jan 2000 12:00:00 GMT");
        
header("Last-Modified: ".gmdate("D, d M Y H:i:s")."GMT");
        
header("Cache-Control: no-store, no-cache, must-revalidate");
        
header("Cache-Control: post-check=0, pre-check=0"false);
        
header("Pragma: no-cache");
        
header("Content-type: image/jpeg");
        
imagejpeg($this->captchanull70);
        exit;
    }
    
    public function 
confCaptcha($p$v) {
        switch(
strtolower($p)):
            case 
"codigos"$this->refCodigos $v; break;
            case 
"fondos"$this->refFondos $v; break;
            case 
"fuentes"$this->refFuentes $v; break;
            case 
"dificultad"$this->refGradoDificultad = ((int)$v >= and (int)$v <= 40) ? (int)$v $this->refGradoDificultad; break;
            case 
"filtro"$this->refFiltro = ($v != false) ? true false; break;
            case 
"lineas"$this->refLineas = ($v != false) ? true false; break;
            case 
"nlineas"$this->refNLineas = ((int)$v >= 1) ? (int)$v $this->refNLineas; break;
            case 
"clineas"$this->refCLineas = ($v != false) ? true false; break;
            case 
"color"$this->refColor = ($c $this->rgbhex2rgb($v)) ? $c : array(0,0,0); break;
            case 
"tamaño"$this->refTamano = (int)$v; break;
            case 
"ancho"$this->ancho = (int)$v; break;
            case 
"alto"$this->alto = (int)$v; break;
            case 
"longitud"$this->refLongitud = ((int)$v >= 1) ? (int)$v $this->refLongitud; break;
            case 
"caracteres": if(is_array($v)) $this->confCaptcha("caracteres",implode("",$v)); else $this->refCaracteres str_split($v); break;
            default: return 
false; break;
        endswitch;
        return 
true;
    }
    
    private function 
generarCodigo() {
        if(!empty(
$this->refCodigos) and file_exists($this->refCodigos)) {
            return 
$this->codigo $this->generarCodigoArchivo();
        }
        return 
$this->codigo $this->generarCodigoAleatorio();
    }
    
    private function 
generarCodigoAleatorio() {
        
$caracteres = (count($this->refCaracteres) < 1) ? array_merge(range('a''z'), range(09)) : $this->refCaracteres;
        
$n count($caracteres);
        
$codigo '';
        while (
strlen($codigo) < $this->refLongitud) {
            
$codigo .= $caracteres[mt_rand(0$n-1)];
        }
        return 
$codigo;
    }
    
    private function 
generarCodigoArchivo() {
        
$codigo file($this->refCodigos);
        
$codigo trim($codigo[array_rand($codigo)]);
        return !empty(
$codigo) ? $codigo $this->generarCodigoAleatorio();
    }
    
    private function 
generarFondo() {
        
$this->ancho = ($this->ancho 1) ? $this->ancho 210;
        
$this->alto = ($this->alto 1) ? $this->alto 70;
        
        if(!empty(
$this->refFondos) and is_dir($this->refFondos)) {
            
$res opendir($this->refFondos);
            
$imagenes = array();
            while(
$archivo readdir($res)) {
                if(!
in_array(pathinfo($archivoPATHINFO_EXTENSION), array("gif""jpg""png"))) {
                    continue;
                }
                
$imagenes[] = $this->refFondos.'/'.$archivo;
            }
            
closedir($res);
        }
        if(
count($imagenes) < 1) {
            
$rs imagecreate($this->ancho$this->alto);
            
imagecolorallocate($rs255255255);
        } else {
            
$aleat $imagenes[array_rand($imagenes)];
            
$info getimagesize($aleat);
            
            
$bg null;
            
            switch (
$info[2]):
                case 
1$bg imagecreatefromgif($aleat); break;
                case 
2$bg imagecreatefromjpeg($aleat); break;
                case 
3$bg imagecreatefrompng($aleat); break;
            endswitch;
            
            
$bg imagerotate($bg,90*rand(1,4),-1);
            
            
$rs imagecreatetruecolor($this->ancho$this->alto);
            
            
imagecopyresampled($rs$bg0000$this->ancho$this->altoimagesx($bg), imagesy($bg));
        }
        
        return 
$this->fondo = ($this->refFiltro == true) ? $this->aplicarFiltro($rs) : $rs;
    }
    
    private function 
generarLineas() {
        for (
$i 0$i $this->refNLineas$i++) {
            if(
$this->refCLineas != true) {
                
$c mt_rand(70250);
                
$clinea imagecolorallocate($this->fondo$c$c$c); 
            } else {
                
$clinea imagecolorallocate($this->fondomt_rand(80250), mt_rand(80250), mt_rand(80250));
            }
            
imageline($this->fondomt_rand(0$this->ancho), mt_rand(0$this->alto), mt_rand(0$this->ancho), mt_rand(0$this->alto), $clinea);
        }
        return;
    }
    
    private function 
aplicarFiltro($rs$ligero 0) {
        
$extra = ($ligero == 1) ? (((int)$this->refGradoDificultad 1) ? (int)$this->refGradoDificultad ) : rand(2030);
        
$rsf imagecreatetruecolor($this->ancho+$extra$this->alto+$extra);
        
$dstH $this->ancho;
        
$srcH $this->ancho $extra;
        
$h rand(510);
        for (
$i 0$i $this->ancho$i++) {
            
$a = (sin(deg2rad(2*$i*$h))+sin(deg2rad($i*$h))) * 1.1;
            
imagecopyresized($rsf$rs$i0$i0$extra+$i$dstH+$extra*$a$extra+$i$srcH);
        }
        return 
$rsf;
    }
    
    private function 
generarTexto() {
        
$t imagecreatetruecolor($this->ancho$this->alto);
        
        
$fcolor = ($this->refColor[0] == 255 and $this->refColor[1] == 255 and $this->refColor[2] == 255) ? imagecolorallocate($t000) : imagecolorallocate($t255255255);
                    
        
imagefill($t00$fcolor);
        
        
$tcolor imagecolorallocate($t$this->refColor[0], $this->refColor[1], $this->refColor[2]);
        
        if(!empty(
$this->refFuentes) and is_dir($this->refFuentes)) {
            
            
$res opendir($this->refFuentes);
            
$fuentes = array();
            while(
$archivo readdir($res)) {
                if(!
in_array(pathinfo($archivoPATHINFO_EXTENSION), array("ttf"))) {
                    continue;
                }
                
$fuentes[] = $this->refFuentes.'/'.$archivo;
            }
            
closedir($res);
            
            
$this->fuentes $fuentes;
            
            
$x 15;
            
            for (
$i 0$i strlen($this->codigo); $i++) {
                
imagettftext($t$this->refTamanorand(-3030), $x$this->refTamano+rand(525), $tcolor$this->fuenteAleatoria(), $this->codigo{$i});
                
$x += $this->refTamano 6;
            }
            
        } else {
            
$tfont rand(3,5);
            
$tancho imagefontwidth($tfont) * strlen($this->codigo);
            
$talto imagefontheight($tfont);
            
$margen $tancho 0.3 5;
            
$ttexto imagecreatetruecolor($tancho $margen$talto $margen);
            
            
imagefill($ttexto00$fcolor); // For GD2+
            
            
$tx $margen 2;
            
$ty $margen 2;
            
            
imagestring($ttexto$tfont$tx$ty$this->codigo$tcolor);
            
            
imagecopyresampled($t$ttexto0000$this->ancho$this->alto$tancho+$margen$talto+$margen);
        }
        
        if (
$this->refFiltro) {
            
$t $this->aplicarFiltro($t1);
        }
        
        
imagecolortransparent($t$fcolor);
        
        return 
$this->texto $t;
        
    }
        
    
}

?>
  #2 (permalink)  
Antiguo 12/07/2008, 11:54
 
Fecha de Ingreso: enero-2008
Ubicación: La Plata
Mensajes: 136
Antigüedad: 16 años, 1 mes
Puntos: 3
Respuesta: Clase que no funciona no se por que

Por que no usas algun captcha mas sencillo?

Como este http://blog.unijimpe.net/crear-captcha-con-php/


Espero que te sirva...
  #3 (permalink)  
Antiguo 12/07/2008, 13:00
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 15 años, 11 meses
Puntos: 2534
Respuesta: Clase que no funciona no se por que

que PHP usas?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
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 10:04.