Ver Mensaje Individual
  #12 (permalink)  
Antiguo 17/09/2015, 18:49
alvaro_trewhela
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Imagen tipo captcha

Gracias me sirvió esto hice:

formulario.php

Código PHP:
Ver original
  1. <?php
  2. ?><html>
  3.     <head>
  4.         <title>Captcha</title>
  5.     </head>
  6.     <body>
  7.         <form method="post" action="procesador.php">
  8.         <img src="captcha.php" /><br />
  9.         Ingrese el captcha<br />
  10.         <input type="text" name="captcha1" /><br/>
  11.         <input style="visibility:hidden;" readonly="readonly" value="<?php echo $_SESSION["captcha"]; ?>" />
  12.         <input type="submit" value="GO !">
  13.         </form>
  14.     </body>
  15. </html>

captcha.php

Código PHP:
Ver original
  1. <?php
  2. $rand = rand(1, 9999999);
  3. $_SESSION["captcha"] = md5($rand);
  4.  
  5.  
  6. header("Content-Type: image/png");
  7. $im = @imagecreate(80, 25) or die("Cannot Initialize new GD image stream");
  8. $background_color = imagecolorallocate($im, 0, 0, 0);
  9. $text_color = imagecolorallocate($im, 225, 14, 91);
  10. imagestring($im, 6, 5, 5, $rand, $text_color);
  11. imagepng($im);
  12.  
  13.  
  14.  
  15. ?>

procesador.php

Código PHP:
Ver original
  1. <?php
  2.  
  3. $c1 = md5($_POST["captcha1"]);
  4. $c2 = $_SESSION["captcha"];
  5.  
  6. if($c1 == $c2){
  7. echo "OK";
  8. }
  9. else{
  10. echo "BAD";
  11. }
  12.  
  13. ?>

Ahora lo voy a integrar a mi pág. a ver si todo anda bien en un código más complejo.