Jump to content

PEAR, Text_CAPTCHA, (image can not be displayed because it has errors)


horseatingweeds

Recommended Posts

I'm trying to use Pear. I just set it up on my test server (work station). I think it's working.

 

Does anyone see what I'm doing wrong?

Anyone know a good way to test if Pear IS in fact working?

 

Here's the code:

 

<?php
class UtilityController extends CustomControllerAction
{
public function captchaAction()
{
	$session = new Zend_Session_Namespace('captcha');
	// Chack for existing phrase in session
	$phrase = null;
	if (isset($session->phrase) && strlen($session->phrase) > 0)
		$phrase = $session->phrase;

	// Call Pear - generate CAPTCHA
	$captcha = Text_CAPTCHA::factory('Image');
	$opts = array('font_size' => 20,
					'font_path' => Zend_Registry::get('config')->paths->data,
					'font_file' => 'VeraBd.ttf');
	// Call the init() method specifying the width, height, and CAPTCHA phrase
	$captcha->init(120, 60, $phrase, $opts);

	// write the phrase to session
	$session->phrase = $captcha->getPhrase();

	// disable auto-rendering since we're outputting an image
	$this->_helper->viewRenderer->setNoRender();

	header('Content-type: image/png');
	echo $captcha->getCAPTCHAAsPng();
}
}
?>

 

 

Link to comment
Share on other sites

What error are you receiving?

 

That's just it: "The image “http://localhost/utility/captcha” cannot be displayed, because it contains errors."

 

You need to show your code that is calling the class function and outputting the image. You are likely outputting content before or after the image or are not using the <img src="...." alt=""> tag properly.

 

I should have been more specific, I'm not even that far yet PFMaBiSmAd. I'm just assessing the class directly.

Link to comment
Share on other sites

Come-on fellows. Yes, I've installed pear - I'm not certain it's working properly, that's why I've asked if anyone knows a good way to test it. I get no errors when calling the script, so I figure it must be.

 

Also, I have GD installed and the other Pear packs Text_Captcha depend on.

 

Anyway, PFMaBiSmAd, when I call this script into the page I'm using it one, the alt text is the only thing that comes up.

 

	<div class="captcha">
	<img src='/utility/captcha' alt='CAPTCHA imge' />
</div>

 

But like I said, if you visit /utility/captcha directly you see the image errors message. If you look at the page source you see about 30 lines of crazy looking code - like when you look at a file with the wrong extension. Is this a Pear error????

 

 

Link to comment
Share on other sites

Well, I've been trying to find an answer to this - no  progress. I tried changing to a JPEG. Instead of getting the error, I just get the file path. Still, if I view the page source, I get the image code. Odd

 

Are captchas really the best way to weed out non-humans? Seriously? I mean, I'm pretty good at figuring them out and I fail about half the time. What the hell to people do that don't see well, or don't understand the captcha conventions? Wouldn't a simple question work better? If you're so randy for an image why not a reasonable image and a question about it.

 

Take an image of a dog licking himself: Is the dog cleaning his balls or his brains?

 

Seriously! You know what I mean?

Link to comment
Share on other sites

I must be doing something fundamentally wrong here. I've tried using the Text_CAPTCHA Pear on another server, also with the go-pear Webbased Pear Package manager.

 

I've tried running this script.

 

<?php

error_reporting(E_ALL);
require_once ($_SERVER['DOCUMENT_ROOT'] . '/pear/PEAR/Text/CAPTCHA.php');
echo $_SERVER['DOCUMENT_ROOT'];

$captcha = Text_CAPTCHA::factory('Image');
$opts = array('font_size' => 20,
		'font_path' => $_SERVER['DOCUMENT_ROOT'] . '/',
		'font_file' => 'VeraBd.ttf');

$captcha->init(120, 60, 'This', $opts);
header('Content-type: image/png');
echo $captcha->getCAPTCHAAsPng();

?>

 

It just creates nothing. Nothing in the source either. Do you treat Pear differently when it's not running with the php installation?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.