Text_CAPTCHA
[ class tree: Text_CAPTCHA ] [ index: Text_CAPTCHA ] [ all elements ]

Source for file CAPTCHA_test.php

Documentation is available at CAPTCHA_test.php

  1. <?php
  2. if (!function_exists('file_put_contents')) {
  3.     function file_put_contents($filename$content$flags = 0{
  4.         if (!($file fopen($filename($flags 1'a' 'w'))) {
  5.             return false;
  6.         }
  7.         $n fwrite($file$content);
  8.         fclose($file);
  9.         return $n $n : false;
  10.     }
  11. }
  12.  
  13. // Start PHP session support
  14.  
  15. $ok = false;
  16.  
  17. $msg "Please enter the text in the image in the field below!";
  18.  
  19. if ($_SERVER["REQUEST_METHOD"== "POST"{
  20.  
  21.     if (isset($_POST["phrase"]&& isset($_SESSION["phrase"]&&
  22.         strlen($_POST["phrase"]> 0 && strlen($_SESSION["phrase"]> 0 &&
  23.         $_POST["phrase"== $_SESSION["phrase"]{
  24.         $msg "OK!";
  25.         $ok = true;
  26.     else {
  27.         $msg "Please try again!";
  28.     }
  29.  
  30.     unlink(session_id(".png");   
  31.  
  32. }
  33.  
  34. print "<p>$msg</p>";
  35.  
  36. if (!$ok{
  37.     
  38.     require_once 'Text/CAPTCHA.php';
  39.                    
  40.     // Generate a new Text_CAPTCHA object, Image driver
  41.     $c Text_CAPTCHA::factory('Image');
  42.     $c->init(20080);
  43.     
  44.     // Get CAPTCHA secret passphrase
  45.     $_SESSION["phrase"$c->getPhrase();
  46.     
  47.     // Get CAPTCHA image (as PNG)
  48.     file_put_contents(session_id(".png"$c->getCAPTCHAAsPNG());
  49.     
  50.     echo "<form method=\"POST\">" 
  51.          "<img src=\"" session_id(".png?" time("\" />" 
  52.          "<input type=\"text\" name=\"phrase\" />" .
  53.          "<input type=\"submit\" /></form>";
  54. }
  55. ?>

Documentation generated on Mon, 11 Mar 2019 13:57:30 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.