Foros del Web » Programando para Internet » PHP »

Captcha

Estas en el tema de Captcha en el foro de PHP en Foros del Web. Hola a tod@s, estoy intentando implementar la image de validación en formulario pero no funciona. He probado el primer código buscando el google: captcha+php (parece ...
  #1 (permalink)  
Antiguo 22/05/2007, 03:20
 
Fecha de Ingreso: mayo-2007
Mensajes: 3
Antigüedad: 17 años
Puntos: 0
Pregunta Captcha

Hola a tod@s,

estoy intentando implementar la image de validación en formulario pero no funciona.

He probado el primer código buscando el google: captcha+php (parece que no puedo poner el link para el tema de spam).

La características del servidor son:
PHP 4.2.2
GD Support enabled
GD Version 1.6.2 or higher
FreeType Support enabled
FreeType Linkage with freetype
JPG Support enabled
PNG Support enabled
WBMP Support enabled

la image no se muestra en el formulario, puede ser algo de la libreria GD, que se necesite la versión 2.0.

Gracias por todo.
Un saludo.
  #2 (permalink)  
Antiguo 22/05/2007, 05:04
Avatar de vb2005  
Fecha de Ingreso: noviembre-2005
Ubicación: Paderborn - Alemania
Mensajes: 566
Antigüedad: 18 años, 5 meses
Puntos: 24
Re: Captcha

depende del tipo de funciones GD que estes usando, muestranos aver que tienes, yo hace un tiempo hice un codigo captcha que sirve mucho tiene más de 36 variantes, en el codigo y muchas otras cosas
  #3 (permalink)  
Antiguo 22/05/2007, 05:57
 
Fecha de Ingreso: mayo-2007
Mensajes: 3
Antigüedad: 17 años
Puntos: 0
Re: Captcha

Veamos, el código es el siguiente:

CaptchaSecurityImages.php

<?php
session_start();

class CaptchaSecurityImages {

var $font = 'monofont.ttf';

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($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}

function CaptchaSecurityImages($width='120',$height='40',$c haracters='6') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_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_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}

}

$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';

$captcha = new CaptchaSecurityImages($width,$height,$characters);

?>

form.php

<?php
session_start();

if( isset($_POST['submit'])) {
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
echo 'Thank you. Your message said "'.$_POST['message'].'"';
unset($_SESSION['security_code']);
} else {
// Insert your code for showing an error message here
echo 'Sorry, you have provided an invalid security code';
}
} else {
?>

<form action="form.php" method="post">
<label for="name">Name: </label><input type="text" name="name" id="name" /><br />
<label for="email">Email: </label><input type="text" name="email" id="email" /><br />
<label for="message">Message: </label><textarea rows="5" cols="30" name="message" id="message"></textarea><br />
<img src="CaptchaSecurityImages.php?width=100&height=40 &characters=5" /><br />
<label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" /><br />
<input type="submit" name="submit" value="Submit" />
</form>

<?php
}
?>

luego el archivo monofont.ttf

Gracias por todo.
Un saludo.
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 18:01.