|
|||
|
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();
}
}
?>
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');
}
}
?>
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();
?>
Any good ideas?? |
|
||||
|
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 |
|
|||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|