Foros del Web » Programando para Internet » PHP »

¿Ayudenme con error de Captcha?

Estas en el tema de ¿Ayudenme con error de Captcha? en el foro de PHP en Foros del Web. Hola a todos tengo un pequeño error con el Captcha, es que no se como poner el código a este mismo y por esa razón ...
  #1 (permalink)  
Antiguo 07/06/2008, 23:12
 
Fecha de Ingreso: abril-2008
Mensajes: 63
Antigüedad: 16 años
Puntos: 1
¿Ayudenme con error de Captcha?

Hola a todos tengo un pequeño error con el Captcha, es que no se como poner el código a este mismo y por esa razón no me deja mandar el comentario, porque no me se el código y necesito cambiarlo.

les mando el código:

captcha.php


<?php
session_start();

require_once('class.simplecaptcha.php');

/*
*****CONFIGURATION STARTS*****
*/
//Background Image
$config['BackgroundImage'] = "white.png";

//Background Color- HEX
$config['BackgroundColor'] = "FFFC00";

//image height - same as background image
$config['Height']=30;

//image width - same as background image
$config['Width']=100;

//text font size
$config['Font_Size']=21;

//text font style
$config['Font']="verdana.TTF";

//text angle to the left
$config['TextMinimumAngle']=15;

//text angle to the right
$config['TextMaximumAngle']=25;

//Text Color - HEX
$config['TextColor']='000000';

//Number of Captcha Code Character
$config['TextLength']=6;

//Background Image Transparency
$config['Transparency']=50;

/*
*******CONFIGURATION ENDS******
*/



//Create a new instance of the captcha
$captcha = new SimpleCaptcha($config);

//Save the code as a session dependent string
$_SESSION['string'] = $captcha->Code;
$_GET["code_captcha"] = $captcha->Code;


?>





class.simplecaptcha.php








<?php
/************************************************** ****************
Projectname: Simple CAPTCHA class
Version: 0.1
Author: Ver Pangonilo <[email protected]>
Last modified: 18 May 2006
Copyright (C): 2006 Ver Pangonilo, All Rights Reserved

* GNU General Public License (Version 2, June 1991)
*
* This program is free software; you can redistribute
* it and/or modify it under the terms of the GNU
* General Public License as published by the Free
* Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License
* for more details.

Description:
This class can generate CAPTCHAs for user forms.

************************************************** ****************/

class SimpleCaptcha {

function SimpleCaptcha( $params = null )
{
$this->BackgroundImage = $params['BackgroundImage']; //background image
$this->BackgroundColor = $params['BackgroundColor'];
$this->Height = $params['Height']; //image height
$this->Width = $params['Width']; //image width
$this->FontSize = $params['Font_Size']; //text font size
$this->Font = $params['Font']; //text font style
$this->TextMinimumAngle = $params['TextMinimumAngle'];
$this->TextMaximumAngle = $params['TextMaximumAngle'];
$this->TextColor = $params['TextColor'];
$this->TextLength = $params['TextLength'];
$this->Transparency = $params['Transparency'];

$this->generateCode();
//initially, png is used
header("Content-type: image/png");
$this->generateImage($this->Code);

}
//Background Images
function getBackgroundImage()
{
return $this->BackgroundImage;
}

function setBackgroundImage( $background_image = null )
{
$this->BackgroundImage = $background_image;
}

//Backgroung Color
function getBackgroundColor()
{
return $this->BackgroundColor;
}

function setBackgroundColor( $background_color )
{
$this->BackgroundColor = $background_color;

}

//Image Height
function getHeight()
{
return $this->Height;
}

function setHeight( $height = null )
{
$this->Height = $height;
}
//Image Width
function getWidth()
{
return $this->Width;
}

function setWidth( $width = null )
{
$this->Width = $width;
}
//Font size
function getFontSize()
{
return $this->FontSize;
}

function setFontSize( $size = null )
{
$this->FontSize = $size;
}

//Font
function getFont()
{
return $this->Font;
}

function setFont( $font = null )
{
$this->Font = $font;
}

//Text Minimum Angle
function getTextMinimumAngle()
{
return $this->TextMinimumAngle;
}

function setTextMinimumAngle( $minimum_angle = null )
{
$this->TextMinimumAngle = $minimum_angle;
}

//Text Maximum Angle
function getTextMaximumAngle()
{
return $this->TextMaximumAngle;
}

function setTextMaximumAngle( $maximum_angle = null )
{
$this->TextMaximumAngle = $maximum_angle;
}

//Text Color
function getTextColor()
{
return $this->TextColor;
}

function setTextColor( $text_color )
{
$this->TextColor = $text_color;
}

//Text Length
function getTextLength()
{
return $this->TextLength;
}

function setTextLength( $text_length = null )
{
$this->TextLength = $text_length;
}

//Transparency
function getTransparency()
{
return $this->Transparency;
}

function setTransparency( $transparency = null )
{
$this->Transparency = $transparency;
}

//get Captcha Code
function getCode()
{
return $this->Code;
}

//Generate Captcha
function generateCode()
{
$length = $this->getTextLength();
$this->Code = "";
while(strlen($this->Code)<$length){
mt_srand((double)microtime()*1000000);
$random=mt_rand(48,122);
$random=md5($random);
$this->Code .= substr($random, 17, 1);
}

return $this->Code;
}


function generateImage($text = null)
{
$im = imagecreatefrompng( $this->getBackgroundImage() );
$tColor = $this->getTextColor();
$txcolor = $this->colorDecode($tColor);
$bcolor = $this->getBackgroundColor();
$bgcolor = $this->colorDecode($bcolor);
$width = $this->getWidth();
$height = $this->getHeight();
$transprency = $this->getTransparency();
$this->im = imagecreate($width,$height);
$imgColor = imagecolorallocate($this->im, $bgcolor[red], $bgcolor[green], $bgcolor[blue]);
imagecopymerge($this->im,$im,0,0,0,0,$width,$height,$transprency);
$textcolor = imagecolorallocate($this->im, $txcolor[red], $txcolor[green], $txcolor[blue]);
$font = $this->getFont();
$fontsize=$this->getFontSize();
$minAngle = $this->getTextMinimumAngle();
$maxAngle = $this->getTextMaximumAngle();
$length = $this->getTextLength();

for($i=0;$i<$length;$i++){
imagettftext(
$this->im,
$fontsize,
rand(-$minAngle,$maxAngle),
$i*15+10,
$this->FontSize*1.2,
$textcolor,
$font,
substr($text, $i, 1));
}

imagepng($this->im);
imagedestroy($this->im);
}

function colorDecode( $hex ){

if(!isset($hex)) return FALSE;

$decoded[red] = hexdec(substr($hex, 0 ,2));
$decoded[green] = hexdec(substr($hex, 2 ,2));
$decoded[blue] = hexdec(substr($hex, 4 ,2));

return $decoded;

}


}

?>



Por favor necesito su ayuda :D
  #2 (permalink)  
Antiguo 08/06/2008, 10:58
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: ¿Ayudenme con error de Captcha?

yo no veo el error.... sorry

demás, el código de la clase.... es irrelevante
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 08/06/2008, 12:09
 
Fecha de Ingreso: mayo-2007
Ubicación: Lima/Peru
Mensajes: 25
Antigüedad: 16 años, 11 meses
Puntos: 0
Respuesta: ¿Ayudenme con error de Captcha?

yo hago el captcha un poco diferente pero = funka haver si te agrada.

primero creu un archivo llamado crear_imagen.php

<?php
//creamos la imagen definiendo el tamaño del alto y el ancho (150, 40)
$captcha_imagen = imagecreate(150,40);
//creamos el color negro para el fondo y blanco para los caracteres
$color_negro = imagecolorallocate ($captcha_imagen, 0, 0, 0);
$color_blanco = imagecolorallocate ($captcha_imagen, 255, 255, 255);
//pintamos el fondo con el cplor negro creado anteriormente
imagefill($captcha_imagen, 0, 0, $color_negro);
//iniciamos la session para obtener los caracteres a dibujar
session_start();
$captcha_texto = $HTTP_SESSION_VARS["captcha_texto_session"];
//dibujamos los caracteres de color blanco
imagechar($captcha_imagen, 4, 20, 13, $captcha_texto[0] ,$color_blanco);
imagechar($captcha_imagen, 5, 40, 13, $captcha_texto[1] ,$color_blanco);
imagechar($captcha_imagen, 3, 60, 13, $captcha_texto[2] ,$color_blanco);
imagechar($captcha_imagen, 4, 80, 13, $captcha_texto[3] ,$color_blanco);
imagechar($captcha_imagen, 5, 100, 13, $captcha_texto[4] ,$color_blanco);
imagechar($captcha_imagen, 3, 120, 13, $captcha_texto[5] ,$color_blanco);
//indicamos que lo que vamos a mostrar es una imagen
header("Content-type: image/jpeg");
//mostramos la imagen
imagejpeg($captcha_imagen);
?>

otro archivo que diga verificar.php

<?php
session_start();
$texto_ingresado = $HTTP_POST_VARS["texto_ingresado"];
$captcha_texto = $HTTP_SESSION_VARS["captcha_texto_session"];
if ($texto_ingresado == $captcha_texto) {
echo "Usted ingreso el codigo correctamente.";
} else {
echo "El texto ingresado no coincide. Por favor intentelo de nuevo!";
}
session_unset();
session_destroy();
?>

y finalmente index.php

<?php
session_start();
$captcha_texto = "";
for ($i = 1; $i <= 6; $i++) {
$captcha_texto .= caracter_aleatorio();
}
$HTTP_SESSION_VARS["captcha_texto_session"] = $captcha_texto;
function caracter_aleatorio() {
$valor_aleatorio = mt_rand(1,3);
switch ($valor_aleatorio) {
case 1:
$valor_aleatorio = mt_rand(97, 122);
break;
case 2:
$valor_aleatorio = mt_rand(48, 57);
break;
case 3:
$valor_aleatorio = mt_rand(65, 90);
break;
}
return chr($valor_aleatorio);
}
?>
<p>Captcha: Formularios mas seguros.</p>
<hr size="1" noshade="noshade" />
<p>Por favor ingrese el codigo que ve en la imagen, sino puede leerlo actualize la pagina.</p>
<p align="center"><img src="crear_imagen.php?<?php echo SID; ?>" /></p>
<form action=verificar.php method="POST">
<p>Ingrese el codigo:
<input name="texto_ingresado" type="text" id="texto_ingresado" size="30" />
<input type="submit" name="Submit" value="OK" />
</p>
</form>
<p><b>Nota:</b> El codigo es sensible a las mayusculas y minisculas</p>

y ya tienes un ejemplo de como.
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 21:32.