This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Headers already sent by PHP
I am new to zend.I tried to create simple form having two fields using zend. When i click submit button got the following error,
Fatal error: Uncaught exception 'Zend_Controller_Response_Exception' with message 'Cannot send headers; headers already sent in D:\xampp\htdocs\study\quickstart\application\controllers\EmployeeController.php, line 35' in D:\xampp\php\PEAR\Zend\Controller\Response\Abstract.php:282 Stack trace: #0 D:\xampp\php\PEAR\Zend\Controller\Response\Abstract.php(300): Zend_Controller_Response_Abstract->canSendHeaders(true) #1 D:\xampp\php\PEAR\Zend\Controller\Response\Abstract.php(727): Zend_Controller_Response_Abstract->sendHeaders() #2 D:\xampp\php\PEAR\Zend\Controller\Front.php(984): Zend_Controller_Response_Abstract->sendResponse() #3 D:\xampp\php\PEAR\Zend\Application\Bootstrap\Bootstrap.php(77): Zend_Controller_Front->dispatch() #4 D:\xampp\php\PEAR\Zend\Application.php(358): Zend_Application_Bootstrap_Bootstrap->run() #5 D:\xampp\htdocs\study\quickstart\public\index.php(25): Zend_Application->run() #6 {main} thrown in D:\xampp\php\PEAR\Zend\Controller\Response\Abstract.php on line 282
I checked the following link,
zend header already send problem
I removed white spaces and gave close tag in all files, But still i am getting same error.
How to fix this error ?
Following shows EmployeeController.php:
<?php
class EmployeeController extends Zend_Controller_Action
{
public function init()
{
}
public function indexAction()
{
$form = new Default_Form_Empdetails();
$this->view->form = $form;
$request = $this->getRequest();
$formData = $request->getPost();
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
$empName = $form->getValue('empName');
$empAddress = $form->getValue('empAddress');
$emp = new Default_Model_DBTable_Employee();
$emp->addAlbum($empName, $empAddress);
$this->_helper->redirector('index');
} else {
$form->populate($formData);
}
}
}
}
?>
Kindly help me
It may be because of extra white spaces after php closing tag (?>) in some file.
Also read this Post:
PHP development: why redirects don't work (headers already sent)
Any HTML output, including the DOCTYPE declaration or any HTML tag,
including the head of the page
Extra whitespace before the opening PHP tag of the page, or outside the
PHP tags of an include file
Using print() or echo before calling header() or session_start()
Using virtual() to include files
Using the byte-order mark (BOM) at the beginning of a page
For example:
Related
I don't know why but my pdf batch does'nt work and now I have this error.
The problem come from the class inside the while loop
Thank you
Notice: OM\Registry::set - Order already registered and is not forced to be replaced in /home/www/shop/includes/OM/Registry.php on line 33
Fatal error: Uncaught Exception: FPDF error: Some data has already been output, can't send PDF file in /home/www/boutique/ext/fpdf/fpdf.php:271 Stack trace: #0 /home/www/boutique/ext/fpdf/fpdf.php(1063): FPDF->Error('Some data has a...') #1 /home/www/boutique/ext/fpdf/fpdf.php(999): FPDF->_checkoutput() #2 /home/www/boutique/admin/invoice_batch.php(570): FPDF->Output() #3 {main} thrown in /home/www/boutique/ext/fpdf/fpdf.php on line 271
This error is in relation with this element
// Classe pdf.php
$pdf = new \FPDF();
// $pdf->SetWidths(array(30,50,30,40));
while ($QordersInfo->fetch()) {
Registry::set('Order', new OrderAdmin($QordersInfo->valueInt('orders_id')));
$order = Registry::get('Order');
...
..
}
// PDF's created no
// output the file
$pdf->Output();
If I write this it "works perfectly" but it display only 1 invoice.
// Classe pdf.php
$pdf = new \FPDF();
// $pdf->SetWidths(array(30,50,30,40));
while ($QordersInfo->fetch()) {
Registry::set('Order', new OrderAdmin($QordersInfo->valueInt('orders_id')));
$order = Registry::get('Order');
.....
// output the file
$pdf->Output();
}
It is difficult to trace the problem without knowing what Registry::set() does, but it looks like the first parameter of that function should be a unique key. In your code the key is always 'Order' in every iteration of the loop. The first iteration will be fine, but in the second iteration it will generate output to give you a Notice that there already is a Registry entry with that key.
The $pdf->Output() function checks to see if anything in your PHP code has already produced any output. Because the Notice was sent to output, FPDF cannot start rendering and produces the FPDF error to let you know.
Either use a unique key (perhaps the ID of the order?) or force the Registry entry to be replaced in every iteration. If that does not get you on track again, post the Registry class code so we can delve deeper into the problem.
I'm trying to use Zebra_form in a metabox for a Wordpress plugin I'm working on.
For simplicity I reduced the code to this:
public function render_metabox( $post ) {
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// the label for the "email" field
$form->add('label', 'label_email', 'email', 'Email');
// add the "email" field
$obj = $form->add('text', 'email', '', array('autocomplete' => 'off'));
// auto generate output, labels above form elements
$form->render();
}
But I get the following error when I try to run it:
Warning: Cannot modify header information - headers already sent by (output started at /Users/dp/Documents/SitesDev/wordpress/wp-admin/includes/template.php:1877) in /Users/dp/Documents/SitesDev/wordpress/wp-content/plugins/my-plugin/lib/Zebra/Zebra_Form.php on line 4052
Fatal error: The library tried to store the CSRF token in a cookie but was unable to do so because there was output already sent to the browser. You should either start a session prior to instantiating the library (recommended), have no output (including and tags, as well as any whitespace) sent to the browser prior to instantiating the library, or turn output buffering on in php.ini. in /Users/dp/Documents/SitesDev/wordpress/wp-content/plugins/my-plugin/lib/Zebra/Zebra_Form.php on line 4052
Any clues? Or Zebra_form cannot be used in this way?
I know it has been a while since you posted this question but here is where I came up with
I got the same error as you so I looked in the Zebra_Form.php and commented out line 4041 to line 4068.
It worked after.
you have to put
session_start();
I'm new to the yii framework and I am trying to execute a php application in my local zwamp environment. The application works correctly in a production environnent.
The Error I receive is after filling the form and trying to submit it. The captcha doesn't validate and I get the following error in the logs:
2014/11/10 10:23:17 [error] [exception.CHttpException.404] exception 'CHttpException' with message 'The system cannot find the action « undefined » that is requested.' in D:\Users\....\web\CController.php:483
Stack trace:
#0 D:\Users\...\web\CController.php(270): CController->missingAction('undefined')
#1 D:\Users\...\web\CWebApplication.php(282): CController->run('undefined')
#2 D:\Users\...\web\CWebApplication.php(141): CWebApplication->runController('site/undefined')
#3 D:\Users\...\base\CApplication.php(180): CWebApplication->processRequest()
#4 D:\Users\....\index.php(23): CApplication->run()
#5 {main}
REQUEST_URI=/appname/site/undefined
HTTP_REFERER=http://localhost:92/appname/site/form
How can I fix this or identify which action is causing the problem?
**EDIT: problem seems to come from here : the verification code does not match the image displayed.. **
/**
* Gets the verification code.
* #param boolean $regenerate whether the verification code should be regenerated.
* #return string the verification code.
*/
public function getVerifyCode($regenerate=false)
{
if($this->fixedVerifyCode !== null)
return $this->fixedVerifyCode;
$session = Yii::app()->session;
$session->open();
$name = $this->getSessionKey();
if($session[$name] === null || $regenerate)
{
$session[$name] = $this->generateVerifyCode();
$session[$name . 'count'] = 1;
}
$message = $session[$name];
echo "<script type='text/javascript'>alert('$message');</script>";
return $session[$name];
}
what could be the issue?
Ayrad, the error message is quite ambiguous saying like, "...action « undefined ».....", in general Yii 404 errors specifies name of it (for example, "...Unable to resolve the request "ABC XYZ ...." ).
These kind of errors depend on many things, like, was engine rewrite was enabled, how is your .htacess. At least, how is your "URLManager" looks in your Config.
So, my answer is from my experience from the problem which I faced earlier. Their are some broken links in my CSS file, so I got error likes this,
[error] [exception.CHttpException.404] exception 'CHttpException' with message 'The system is unable to find the requested action "undefined".' in C:\wamp\yii\framework\web\CController.php:484
Stack trace:
#0 C:\wamp\yii\framework\web\CController.php(271): CController->missingAction('undefined')
#1 C:\wamp\yii\framework\web\CWebApplication.php(283): CController->run('undefined')
#2 C:\wamp\yii\framework\web\CWebApplication.php(142): CWebApplication->runController('site/undefined')
#3 C:\wamp\yii\framework\base\CApplication.php(162): CWebApplication->processRequest()
#4 C:\wamp\www\index.php(27): CApplication->run()
#5 {main}
REQUEST_URI=/site/undefined
HTTP_REFERER=http://localhost/site/index
I checked my main layout and find out this buggy javascript function causes that error:
$(".shortcuts").each(function(){
var cacheImage = document.createElement('img');
cacheImage.src = $(this).attr('rel');
cache.push(cacheImage);
});
It was suppose to preload shortcuts images on the bootstrap navbar. so that fixed the problem. Hope this helps. if not, please try to post extra details.
Error logs show clearly what this is about,
REQUEST_URI=/appname/site/undefined
this shows that somehow you generated a url like that and when it was trying to resolve using that, it faild (I think it's your forms url)
you have to share to view that made this form, otherwise we can't help you
If this code working correctly in production environment. Then the issue may be due to mismatch of database or main.php. I think, this error is due to not getting the site action correctly. check that, the requesting URL is given correctly.
I'm having following Zend Session error with my zend project:
Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Zend_Session::start() - /home/besthomes/public_html/Zend/Session.php(Line:426): Error #2 session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/besthomes/public_html/Zend/Exception.php:1) Array' in /home/besthomes/public_html/Zend/Session.php:432 Stack trace: #0 /home/besthomes/public_html/index.php(47): Zend_Session::start() #1 {main} thrown in /home/besthomes/public_html/Zend/Session.php on line 432
I have wrote this code in bootstrap file:
include('include.php');
include "Zend/Loader.php";
Zend_Loader::registerAutoload();
Zend_Session::start();
i couldn't know the reason for this error. please help to get out of this problem.
Thanks.
Check if you don't have additional characters in your files. For example -
this code won't trigger an error:
<?php
session_start();
but that one will:
(blank line here!)
<?php
session_start();
Same thing applies to included files. But, when you include files you must also notice to do not have additional lines after clossing tag (if you use them). This will work:
<?php
//content of included file
?>
but something like that won't:
<?php
//content of included file
?>
(blank line here!)
(!and here)
So that's why some people consider not using closing tag in php scripts as good practice.
You can also workaround that problem using ob_start and ob_end_flush, but like I said - it's workaround, not solution.
Somewhere in your code, there is some output being done, which PHP will send the HTTP headers for. Since the HTTP headers are already sent, they cannot be sent again when trying to start the session. If you want to use sessions, starting the session early or first thing is a good idea.
On the other hand, I've seen this error when my app outputs a separate error, thus sending the HTTP headers.
Please have a look at the docs for further information:
http://framework.zend.com/manual/en/zend.session.html
Namely the section called "Starting a Session":
http://framework.zend.com/manual/en/zend.session.advanced_usage.html
Tip:
Remove/comment out the lines that start the session, and see what is output. There may be another error, even unrelated to your code.
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
I got this error while adding products to the cart in my site:
Cannot send headers; headers already sent in /home/website/public_html/app/code/local/Perpetual/MultiAdd/controllers/Checkout/CartController.php, line 153
Trace:
#0 /home/website/public_html/lib/Zend/Controller/Response/Abstract.php(147): Zend_Controller_Response_Abstract->canSendHeaders(true)
#1 /home/website/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(585): Zend_Controller_Response_Abstract->setRedirect('http://www.trum...')
#2 /home/website/public_html/app/code/core/Mage/Checkout/controllers/CartController.php(85): Mage_Core_Controller_Varien_Action->_redirect('checkout/cart')
#3 /home/website/public_html/app/code/local/Perpetual/MultiAdd/controllers/Checkout/CartController.php(203): Mage_Checkout_CartController->_goBack()
#4 /home/website/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(376): Perpetual_MultiAdd_Checkout_CartController->addmultipleAction()
#5 /home/website/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(248): Mage_Core_Controller_Varien_Action->dispatch('addmultiple')
#6 /home/website/public_html/app/Mage.php(459): Mage_Core_Controller_Varien_Front->dispatch()
#7 /home/website/public_html/wholesale/index.php(65): Mage::run('wholesale', 'website')
#8 {main}
Edit: Disabled extraneous plugin and that did not solve issue.
It appears that headers are sent in line #1 and attempted to be sent again in the file referenced in the error, CartController.php -
$url = $this->_getSession()->getRedirectUrl(true)
if ($url) {
$this->getResponse()->setRedirect($url);
} else {
$this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
}
Any ideas on how to stop Magento from sending headers before Mage does?
There should be a module settings file in app/etc/modules/ with a boolean in it. Disabling a module output doesn't disable the module. Only its output.
Removing the module from the community folder should do the job, but it could be dirty depending on whether this plugin has created tables on your database or not.
Suspicious module disabled?
Ok, let's go for another answer then.
First, check whether you get any output before the error stack trace. An output provokes the sending of headers for this output.
GO var/report and find out the problem file.
Check if there is any space before