Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/05/2010, 11:27
cslbcn
 
Fecha de Ingreso: marzo-2008
Mensajes: 383
Antigüedad: 16 años, 1 mes
Puntos: 5
Error en generador de imagen anti-bots

Hola. He bajé este ejemplo de creación de imagenes automática anti-bots y tengo un problema...

Este es el código:

principal.php
Código PHP:
Ver original
  1. <?php
  2.  
  3. if ($_POST["action"] == "checkdata") {
  4.     if ($_SESSION['tmptxt'] == $_POST['tmptxt']) {
  5.         echo "Bienvenido";
  6.     } else {
  7.         echo "Intentalo nuevamente";
  8.     }
  9.     exit;
  10. }
  11. ?>
  12. <html>
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  15. <title>CAPTCHA con PHP</title>
  16. <meta name="description" content="CAPTCHA con PHP: ejemplo para demostrar la creacion de Captcha con PHP." />
  17. <link href="styles.css" rel="stylesheet" type="text/css">
  18. </head>
  19. <body>
  20. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  21.   <tr>
  22.     <td align="center" class="descdet">
  23.     <div class="bordeder">
  24.         <strong class="subder">CAPTCHA con PHP </strong><br>
  25.         Ingresar el texto mostrado en la imagen <br>
  26.         <form action="principal.php" method="post">
  27.           <img src="crear_imagen.php" width="100" height="30" vspace="3"><br>
  28.           <input name="tmptxt" type="text" size="30"><br>
  29.           <input name="btget" type="submit" class="boton" value="Verificar Codigo">
  30.           <input name="action" type="hidden" value="checkdata">
  31.         </form>
  32.     </div>
  33.     </td>
  34.   </tr>
  35. </table>
  36. </body>
  37. </html>


crear_imagen.php
Código PHP:
Ver original
  1. <?php
  2. function randomText($length) {
  3.     $pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
  4.     for($i=0;$i<$length;$i++) {
  5.       $key .= $pattern{rand(0,35)};
  6.     }
  7.     return $key;
  8. }
  9.  
  10. $_SESSION['tmptxt'] = randomText(8);
  11. $captcha = imagecreatefromgif("bgcaptcha.gif");
  12. $colText = imagecolorallocate($captcha, 0, 0, 0);
  13. imagestring($captcha, 5, 16, 7, $_SESSION['tmptxt'], $colText);
  14.  
  15. header("Content-type: image/gif");
  16. imagegif($captcha);
  17. ?>



El problema está en principal.php en la línea que pone
Código PHP:
Ver original
  1. if ($_POST["action"] == "checkdata") {

Este es el error: Notice: Undefined index: action in C:\Archivos de programa\EasyPHP-5.3.2i\www\principal.php on line 4

Dice que no hay nada... inicialmente si que no hay nada pero al pulsar el submit del formulario debería recoger el valor del input hidden....

Como se puede arreglar? Gracias!

Última edición por cslbcn; 18/05/2010 a las 12:09