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();
}
}
?>

 

 

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.

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.

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????

 

 

That's one of the things I'm confused about actually. I have a shared host without root access. So, on my test server I've set things up the same way. I'm using the go-pear Web based Pear package manager. On the 'Installed Packages' page everything is there.

jonsjava, thanks. The CustomerControllerAction extends Zend_Controller_Action. I gave it a try though, just to see, but no change.

 

PFMaBiSmAd, yeah, that's how I have it set up. The only error is the "image has errors" what-not.

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?

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.