PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Error generating CAPTCHA (maybe font missing?)!

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Text
View previous topic :: View next topic  
Author Message
frankitoy



Joined: 23 Feb 2007
Posts: 1

PostPosted: Fri Feb 23, 2007 4:57 am    Post subject: Error generating CAPTCHA (maybe font missing?)! Reply with quote

i need help pls to solve this code
it outputs "Error generating CAPTCHA (maybe font missing?)!"

if (!function_exists('file_put_contents')) {
function file_put_contents($filename, $content) {
if (!($file = fopen($filename, 'w'))) {
return false;
}
$n = fwrite($file, $content);
fclose($file);
return $n ? $n : false;
}
}

// Start PHP session support
session_start();

$ok = false;

$msg = 'Please enter the text in the image in the field below!';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

if (isset($_POST['phrase']) && isset($_SESSION['phrase']) &&
strlen($_POST['phrase']) > 0 && strlen($_SESSION['phrase']) > 0 &&
$_POST['phrase'] == $_SESSION['phrase']) {
$msg = 'OK!';
$ok = true;
unset($_SESSION['phrase']);
} else {
$msg = 'Please try again!';
}

unlink(md5(session_id()) . '.png');

}

print "<p>$msg</p>";

if (!$ok) {

require_once 'Text/CAPTCHA.php';

// Set CAPTCHA image options (font must exist!)
$imageOptions = array(
'font_size' => 24,
);

// Set CAPTCHA options
$options = array(
'width' => 200,
'height' => 80,
'output' => 'png',
'imageOptions' => $imageOptions
);

// Generate a new Text_CAPTCHA object, Image driver
$c = Text_CAPTCHA::factory('Image');
$retval = $c->init($options);
if (PEAR::isError($retval)) {
echo 'Error initializing CAPTCHA!';
exit;
}

// Get CAPTCHA secret passphrase
$_SESSION['phrase'] = $c->getPhrase();

// Get CAPTCHA image (as PNG)
$png = $c->getCAPTCHA();
if (PEAR::isError($png)) {
echo 'Error generating CAPTCHA (maybe font missing?)!';
exit;
}
file_put_contents(md5(session_id()) . '.png', $png);

echo '<form method="post">' .
'<img src="' . md5(session_id()) . '.png?' . time() . '" />' .
'<input type="text" name="phrase" />' .
'<input type="submit" /></form>';
}
?>
Back to top
View user's profile Send private message Yahoo Messenger
mark



Joined: 07 Jan 2007
Posts: 998

PostPosted: Fri Feb 23, 2007 9:46 am    Post subject: Reply with quote

Replacing
if (PEAR::isError($png)) {
echo 'Error generating CAPTCHA (maybe font missing?)!';
exit;
}

by
if (PEAR::isError($png)) {
die($png->getMessage() . '<br />' . $png->getDebugInfo());
}

will tell you more.
Back to top
View user's profile Send private message
robertos



Joined: 17 Mar 2007
Posts: 32

PostPosted: Sat Mar 17, 2007 5:52 pm    Post subject: Reply with quote

Hello,

I'm trying the first example from the Captcha pakage(wich tries to create a png) and i get the following error: Error initializing Image_Text (font missing?!).

This is form from my phpinfo():
./configure...........' '--with-freetype-dir=/usr'...........and this:

GD Support enabled
GD Version bundled (2.0.28 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.2.1

and the command locate ttf | grep -i COUR.TTF gives me:
/usr/share/fonts/msttcorefonts/cour.ttf

so perhaps i should recompile php with a different path to freetype?But i'm not sure exactly which path.......any ideas?Thanks.
Is there a freetype extention available with yum?(I'm using FC6) .

Thanks
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 998

PostPosted: Sat Mar 17, 2007 6:05 pm    Post subject: Reply with quote

Do you have Image_Text installed?
Back to top
View user's profile Send private message
robertos



Joined: 17 Mar 2007
Posts: 32

PostPosted: Sat Mar 17, 2007 6:18 pm    Post subject: Reply with quote

Yes:
pear install Image_Text
pear/Image_Text is already installed and is newer than detected release version 0.5.2beta2
Back to top
View user's profile Send private message
osde.info



Joined: 18 Apr 2007
Posts: 2

PostPosted: Wed Apr 18, 2007 5:44 pm    Post subject: Reply with quote

https://help.ubuntu.com/community/PhpPear

$ sudo -i
# cd /usr/share/php/Image/Canvas
# ln -s /usr/share/fonts/truetype/msttcorefonts/ Fonts
$

http://pear.php.net/bugs/bug.php?id=3487
http://pear.php.net/bugs/bug.php?id=5994
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Text All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software