* @category Text */ /** * * Require PEAR class for error handling. * */ require_once 'PEAR.php'; /** * * Require Text_Password class for generating the phrase. * */ require_once 'Text/Password.php'; /** * * Require Image_Text class for generating the text. * */ require_once 'Image/Text.php'; /** * Text_CAPTCHA - creates a CAPTCHA for Turing tests * * Class to create a Turing test for websites by * creating an image, ASCII art or something else * with some (obfuscated) characters * * @package Text_CAPTCHA */ /* // This is a simple example script 0 && strlen($_SESSION["phrase"]) > 0 && $_POST["phrase"] == $_SESSION["phrase"]) { $msg = "OK!"; $ok = true; } else { $msg = "Please try again!"; } unlink(session_id() . ".png"); } print "

$msg

"; if (!$ok) { require_once 'Text/CAPTCHA.php'; //require_once 'CAPTCHA.php'; // Generate a new Text_CAPTCHA object, Image driver $c = Text_CAPTCHA::factory('Image'); $c->init(200, 80); // Get CAPTCHA secret passphrase $_SESSION["phrase"] = $c->getPhrase(); // Get CAPTCHA image (as PNG) file_put_contents(session_id() . ".png", $c->getCAPTCHAAsPNG()); echo "
" . "" . "" . "
"; } ?> */ class Text_CAPTCHA { /** * Phrase * * @access private * @var string */ var $_phrase; /** * Create a new Text_CAPTCHA object * * @param string $driver name of driver class to initialize * * @return mixed a newly created Text_CAPTCHA object, or a PEAR * error object on error * * @see PEAR::isError() */ function &factory($driver) { if ('' == $driver) { return PEAR::raiseError("No CAPTCHA type specified ... aborting. You must call ::factory() with one parameter, the CAPTCHA type.", true); } include_once "Text/CAPTCHA/Driver/$driver.php"; $classname = "Text_CAPTCHA_Driver_$driver"; $obj =& new $classname; return $obj; } /** * Create random CAPTCHA phrase * * This method creates a random phrase, 8 characters long * * @access private */ function _createPhrase() { $len = 8; $this->_phrase = Text_Password::create($len); } /** * Return secret CAPTCHA phrase * * This method returns the CAPTCHA phrase * * @access public * @return phrase secret phrase */ function getPhrase() { return $this->_phrase; } /** * Place holder for the real init() method * used by extended classes to initialize CAPTCHA * * @access private * @return PEAR_Error */ function init() { return PEAR::raiseError('CAPTCHA type not selected', true); } /** * Place holder for the real _createCAPTCHA() method * used by extended classes to generate CAPTCHA from phrase * * @access private * @return PEAR_Error */ function _createCAPTCHA() { return PEAR::raiseError('CAPTCHA type not selected', true); } /** * Place holder for the real getCAPTCHA() method * used by extended classes to return the generated CAPTCHA * (as an image resource, as an ASCII text, ...) * * @access private * @return PEAR_Error */ function getCAPTCHA() { return PEAR::raiseError('CAPTCHA type not selected', true); } } ?>