Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/01/2009, 19:31
Avatar de jimadri
jimadri
 
Fecha de Ingreso: julio-2006
Ubicación: Buenos Aires
Mensajes: 487
Antigüedad: 17 años, 10 meses
Puntos: 1
Ejemplo practico de captcha

Hola, les dejo el siguiente ejemplo de un form con el famoso captcha para ver si me puede ayudar a terminar esto que por mis conocimientos no puedo.

El form es el siguiente:

Código PHP:
<?php

session_start
();

if (isset(
$_POST['enviar'])){

    if (
$_SESSION['textoImage'] == $_POST['texto']) {
    
        echo 
'<li>correcto';
        exit;
        
} else {

echo 
'<li>incorrecto';
    }
}

?>

<form method="post">
  <table width="362" border="1">
    <tr>
      <td width="197">ingrese su nombre</td>
      <td width="149"><input type="text" name="textfield" id="nombre"></td>
    </tr>
    <tr>
      <td>ingrese su apellido</td>
      <td><input type="text" name="textfield2" id="apellido"></td>
    </tr>
    <tr>
      <td>ingrese texot de la imagen</td>
      <td>
    <img src='captcha.php' />
    <br/>
    <input type="text" name="textfield2" id="texto">      </td>
    </tr>

    <tr>
      <td><input type="submit" name="enviar" id="enviar" value="enviar consulta"></td>
      <td><input type="submit" name="button2" id="button2" value="reestablecer"></td>
    </tr>
  </table>
</form>
y el archivo captcha.php

Código PHP:
<?php

session_start
();

require_once 
'PEAR/Text/CAPTCHA.php';

$captcha Text_CAPTCHA::factory('Image');

$opcionesImg ['font_size'] = '24';
$opcionesImg ['font_path'] = './fuentes/';
$opcionesImg ['font_file'] = 'cour.ttf';
$opcionesImg ['text_color'] = '#660000';
$opcionesImg ['lines_color'] = '#FF9966';
$opcionesImg ['background_color'] = '#FFFFCC';

$captcha->init(20070NULL$opcionesImg);

$_SESSION['textoImagen'] = $captcha->getPhrase();

$imagen $captcha->getCAPTCHAAsPNG();

if (
PEAR::isError($imagen)) {
    
printf('Error: %s',
    
$imagen->getMessage());
    exit;
    
}


echo 
$imagen;

?>
La informacion (que yo no entiendo) la tiene en http://pear.php.net/package/Text_CAPTCHA


Desde ya muchisimas gracias