horseatingweeds Posted April 16, 2008 Share Posted April 16, 2008 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(); } } ?> Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 17, 2008 Share Posted April 17, 2008 What error are you receiving? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 17, 2008 Share Posted April 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
horseatingweeds Posted April 17, 2008 Author Share Posted April 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 17, 2008 Share Posted April 17, 2008 A class definition without an instance of that class and then a call to a class function is meaningless. Quote Link to comment Share on other sites More sharing options...
horseatingweeds Posted April 17, 2008 Author Share Posted April 17, 2008 It's a control class that is calling a Pear class. I'm certain it should be accessible on its own. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 17, 2008 Share Posted April 17, 2008 um... have you *installed* the pear class? Quote Link to comment Share on other sites More sharing options...
horseatingweeds Posted April 17, 2008 Author Share Posted April 17, 2008 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???? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 17, 2008 Share Posted April 17, 2008 I know you installed pear, but did you install the PEAR module: [root@localhost:~]pear install (module name) Quote Link to comment Share on other sites More sharing options...
horseatingweeds Posted April 17, 2008 Author Share Posted April 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
horseatingweeds Posted April 17, 2008 Author Share Posted April 17, 2008 If the module wasn't installed wouldn't the error describe something to that effect? Is there a way to get more info on Pear errors? I'm not getting much from the documentation... Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 17, 2008 Share Posted April 17, 2008 I found one mention on the web about this issue. try this: class UtilityController extends Zend_Controller_Action instead of class UtilityController extends CustomControllerAction Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 17, 2008 Share Posted April 17, 2008 If you turn on the display_errors setting and set error_reporting to E_ALL, php will tell you if there are problems like typo's, variable/class name problems, PEAR problems... Quote Link to comment Share on other sites More sharing options...
horseatingweeds Posted April 17, 2008 Author Share Posted April 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
horseatingweeds Posted April 17, 2008 Author Share Posted April 17, 2008 Is there a php setting I'm missing here or something? Could this be a problem with Pear? Quote Link to comment Share on other sites More sharing options...
horseatingweeds Posted April 17, 2008 Author Share Posted April 17, 2008 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? Quote Link to comment Share on other sites More sharing options...
horseatingweeds Posted April 18, 2008 Author Share Posted April 18, 2008 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.