We’re on EE 2.1.3 Build 20101220
I am testing a custom Addon Module that returns XML data to a Flash movie. Occasionally I get the following error returned:
Message: Cannot modify header information - headers already sent by (output started at /home/b2bdev/system/expressionengine/third_party/b2b_survey/mod.b2b_survey.php:195) Filename: core/Common.php Line Number: 409
Line 195 of mod.b2b_survey.php is the “echo ‘<short_desc>…’” line shown below. Sometimes the error is also reported as line 196. It only seems to occur when the XML is over 100 lines.
The surrounding code is:
$this->EE->db->select('channel_data.entry_id, title, field_id_3, field_id_5');
$this->EE->db->join('channel_titles', 'channel_data.entry_id = channel_titles.entry_id');
$this->EE->db->where('status', 'open');
$this->EE->db->where_in('exp_channel_data.entry_id', $resources);
$query = $this->EE->db->get('channel_data');
// XML results
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
echo '<resources>' . "\n";
foreach ($query->result_array() as $row)
{
echo ' <resource>' . "\n";
echo ' <entry_id>' . $row['entry_id'] . '</entry_id>' . "\n";
echo ' <title>' . $row['title'] . '</title>' . "\n";
echo ' <short_desc>' . $row['field_id_3'] . '</short_desc>' . "\n";
echo ' <image>' . $this->EE->typography->parse_type($row['field_id_5'], array('text_format' => 'none')) . '</image>' . "\n";
echo ' <objectives>' . "\n";
// objectives
foreach ($objectives[$row['entry_id']] as $objective)
{
echo ' <objective>' . $labels[$objective] . '</objective>' . "\n";
}
echo ' </objectives>' . "\n";
echo ' </resource>' . "\n";
}
echo '</resources>' . "\n";Any idea on what could be causing this?
I tried the following:
Set Debug Preferences to 0:No PHP/SQL messages generated. It resolved this issue - BUT caused an front-end template with this code:
$('.modal').fancybox({
'swf' : {allowScriptAccess : 'always', wmode : 'transparent'}
});to truncate the ‘swf’ parameter and render as which caused jquery errors
$('.modal').fancybox({
'swf' :
});I have also set Generate HTTP Page Headers to NO. It corrected the PHP header error, but what am I risking elsewhere in the site by doing that?
Hi Moe 2.0,
Sorry to see that you are having this trouble. Since the problem is related to your custom add-on we are unable to provide support on this. If you would like I could move this thread to “development and programming” so that the community could assist you.
I would also recommend that you upgrade to the latest version of ExpressionEngine 2.4.0, if possible, as there have been many fixes and improvements since 2.1.3.
Hi Moe,
Is this portion of code being called from a template? Or is it in an Action ID or something else?
I would recommend writing all of the code to a variable and either returning the variable (if called in a template) or echoing it out at the end of execution.
So your code would become something like the following
$return_data = '';
$return_data .= '<?xml version="1.0" encoding="utf-8"?>' . "\n";
$return_data .= '<resources>' . "\n";
....
echo $return_data;
//or
return $return_data;-Tom Jaeger
The code being called is in an action ID.
I tried writing everything to the variable and echoing at the end of execution. I get the same result on the echo statement.
Message: Cannot modify header information - headers already sent by (output started at /home/b2bdev/system/expressionengine/third_party/b2b_survey/mod.b2b_survey.php:231)
Filename: core/Common.php
Line Number: 409
It appears EE’s core/Common.php is trying to send HTTP header of “HTTP/1.1 200 Ok” after the echo statement.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.