require_once 'Text/CAPTCHA.php';
// Set CAPTCHA options (font must exist!)
$options = array(
'font_size' => 24,
'font_path' => './',
'font_file' => 'COUR.TTF'
);
// Generate a new Text_CAPTCHA object, Image driver
$c = Text_CAPTCHA::factory('Image');
$retval = $c->init(200, 80, null, $options);
if (PEAR::isError($retval)) {
echo 'Error generating CAPTCHA!';
exit;
}
// Get CAPTCHA secret passphrase
$_SESSION['phrase'] = $c->getPhrase();
// Get CAPTCHA image (as PNG)
$png = $c->getCAPTCHAAsPNG();
if (PEAR::isError($png)) {
echo 'Error generating CAPTCHA!';
exit;
}
file_put_contents(md5(session_id()) . '.png', $png); |