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.     session_start();
  15.  
  16.     $ok = false;
  17.  
  18.     $msg 'Please enter the text in the image in the field below!';
  19.  
  20.     if ($_SERVER['REQUEST_METHOD'== 'POST'{
  21.  
  22.         if (isset($_POST['phrase']&& isset($_SESSION['phrase']&&
  23.             strlen($_POST['phrase']> 0 && strlen($_SESSION['phrase']> 0 &&
  24.             $_POST['phrase'== $_SESSION['phrase']{
  25.             $msg 'OK!';
  26.             $ok = true;
  27.         else {
  28.             $msg 'Please try again!';
  29.         }
  30.  
  31.         unlink(session_id('.png');   
  32.  
  33.     }
  34.  
  35.     print "<p>$msg</p>";
  36.  
  37.     if (!$ok{
  38.     
  39.         require_once 'Text/CAPTCHA.php';
  40.                    
  41.         // Generate a new Text_CAPTCHA object, Image driver
  42.         $c Text_CAPTCHA::factory('Image');
  43.         $c->init(20080);
  44.     
  45.         // Get CAPTCHA secret passphrase
  46.         $_SESSION["phrase"$c->getPhrase();
  47.     
  48.         // Get CAPTCHA image (as PNG)
  49.         file_put_contents(session_id('.png'$c->getCAPTCHAAsPNG());
  50.     
  51.         echo "<form method=\"POST\">" 
  52.              "<img src=\"" session_id(".png?" time("\" />" 
  53.              "<input type=\"text\" name=\"phrase\" />" .
  54.              "<input type=\"submit\" /></form>";
  55.     }
  56. ?>

Documentation generated on Mon, 11 Mar 2019 14:20:08 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.