Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-19-2008, 03:06 AM
Junior Member
 
Join Date: Apr 2008
Posts: 18
Default captcha image getting corupted

For some reason when I add a captcha (I'm using a Pear script) to this control it becomes corrupt and displays this error: "The image “http://localhost/phpweb20/utility/captcha” cannot be displayed, because it contains errors." If I look at the source of the page there is the binary image code. One suspicion I have is that the cause in the image code might be a blank line at the top... I don't know.

Here is the control code the captcha is in:

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();
	}
}
?>
Here is the CustomControllerAction
Code:
<?php
class CustomControllerAction extends Zend_Controller_Action
{
	public $db;
	
	// init() is automatically called by Zend_Controller_Front
	public function init()
	{
		// fetches database handle from the application resistry and stores it in db property, and makes it available to all controllers $this->db
		$this->db = Zend_Registry::get('db');
	}
}
?>
And here is the index
Code:
<?php
// registerAutoload() automatically loads Zend Framework classes ( except for Zend_Loader )
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();

//load the application configuration
$config = new Zend_Config_Ini('templates/settings.ini', 'development');
Zend_Registry::set('config', $config);

// creat the application logger
$logger = new Zend_log(new Zend_Log_Writer_Stream($config->logging->file));
Zend_Registry::set('logger', $logger);

// Connect to the database
$params = array('host'		=> $config->database->hostname,
				'username'	=> $config->database->username,
				'password'	=> $config->database->password,
				'dbname'	=> $config->database->database);
				
$db = Zend_Db::factory($config->database->type, $params);
// writes $db object to the Zend_Registry so we can use it throughout the application
Zend_Registry::set('db', $db);

// setup application authentication
$auth = Zend_Auth::getInstance();
$auth->setStorage(new Zend_Auth_Storage_Session());

// handle the user request ( controller/action ) 
$controller = Zend_Controller_Front::getInstance();
$controller->setControllerDirectory($config->paths->base . '/includes/Controllers');
$controller->registerPlugin(new CustomControllerAclManager($auth));

// set the view renderer
// Makes Zend_Controller use Templater class instead of its default Zend_View class.
// Zend_Controller will now automatically look for a template based on the controller and action name
$vr = new Zend_Controller_Action_Helper_ViewRenderer();
$vr->setView(new Templater());
$vr->setViewSuffix('tpl');
Zend_Controller_Action_HelperBroker::addHelper($vr);

//$controller->throwExceptions(true);

// make the request
$controller->dispatch();



?>
I've run a simple test, calling the Pear script, that works fine - displaying the captcha image. If I place that simple test in the captcha function of the utility class, it fails with the above error.

Any good ideas??
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 04:35 AM
Ewok's Avatar
Junior Member
 
Join Date: Mar 2008
Location: Colorado SPrings
Posts: 16
Send a message via MSN to Ewok Send a message via Yahoo to Ewok
Default

I'd look at your URL rewrite...
(This is the second time today, I sound like a broken record)
It seems it may be looking for a controller called captcha and returning the error view.

If you put http://localhost/phpweb20/utility/captcha into your browser, do you get the error controller?
__________________
Give all victory and gain to others
Take all defeat and loss upon yourself
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 05:47 AM
Junior Member
 
Join Date: Apr 2008
Posts: 18
Default

I am suspecting this as well. But yes, when I reach the script directly http://localhost/phpweb20/utility/captcha I get the error I described.

I don't know much about document rewrite. Why would it not produce the image by accessing the file this way? Or better, what can I do about it?

Last edited by horseatingweeds : 04-19-2008 at 07:01 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 06:20 PM
Ewok's Avatar
Junior Member
 
Join Date: Mar 2008
Location: Colorado SPrings
Posts: 16
Send a message via MSN to Ewok Send a message via Yahoo to Ewok
Default

You could create a utility/captcha.phtml in your views/scripts folder, then in your catchaAction() set $this->view->captcha = $captcha->getCAPTCHAAsPng() instead of just echoing it in the action.

Then in the captcha.phtml just echo $this->captcha.

You may also need to set the view to be of type PNG. I've never done this so I'm not sure where to start.
__________________
Give all victory and gain to others
Take all defeat and loss upon yourself
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-19-2008, 06:57 PM
Junior Member
 
Join Date: Apr 2008
Posts: 18
Default

Well....

Problem found. I had a blank line at the top of the bootstrap. Good glory...

Thanks for the help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:37 PM.