MyBB Community Forums

Full Version: Cannot modify header information - headers already sent by
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys, I spent about 4 hours solving this problem, but couldn't manage to solve it.

That happens when I'm activating plugin "Show First Post", plugin works but on the top of the page I see these warnings:

Quote:Warning [2] Cannot modify header information - headers already sent by (output started at /var/www/vitz/data/www/vitz55.ru/inc/plugins/show_first_post.php:1) - Line: 3502 - File: inc/functions.php PHP 5.2.6-1+lenny9 (Linux)
File Line Function
[PHP] errorHandler->error
/inc/functions.php 3502 header
/global.php 43 send_page_headers
/showthread.php 22 require_once
Warning [2] Cannot modify header information - headers already sent by (output started at /var/www/vitz/data/www/vitz55.ru/inc/plugins/show_first_post.php:1) - Line: 3503 - File: inc/functions.php PHP 5.2.6-1+lenny9 (Linux)
File Line Function
[PHP] errorHandler->error
/inc/functions.php 3503 header
/global.php 43 send_page_headers
/showthread.php 22 require_once
Warning [2] Cannot modify header information - headers already sent by (output started at /var/www/vitz/data/www/vitz55.ru/inc/plugins/show_first_post.php:1) - Line: 3504 - File: inc/functions.php PHP 5.2.6-1+lenny9 (Linux)
File Line Function
[PHP] errorHandler->error
/inc/functions.php 3504 header
/global.php 43 send_page_headers
/showthread.php 22 require_once
Warning [2] Cannot modify header information - headers already sent by (output started at /var/www/vitz/data/www/vitz55.ru/inc/plugins/show_first_post.php:1) - Line: 3505 - File: inc/functions.php PHP 5.2.6-1+lenny9 (Linux)
File Line Function
[PHP] errorHandler->error
/inc/functions.php 3505 header
/global.php 43 send_page_headers
/showthread.php 22 require_once

I checked file show_first_post.php and there's no any gaps before/after ?php tag.

Here's the content of this file:
<?php

if(!defined("IN_MYBB")) 
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook('showthread_start', 'show_first_post');

function show_first_post_info()
{
	return array(
		"name" => "Show First Post",
		"description" => "Shows first post of the thread in second and next pages",
		"website" => "http://www.mybb.cal.pl",
		"author" => "Jasiu",
		"authorsite" => "http://www.mybb.cal.pl",
		"version" => "1.0.1",
		"compatibility" => "16*"
	);
}
function show_first_post_activate()
{
	require MYBB_ROOT.'/inc/adminfunctions_templates.php';
	global $db;
		$fp_template = array(
		"title"		=> 'global_first_post',
		"template"	=> "<table border=\"0\" cellspacing=\"1\" cellpadding=\"4\" class=\"tborder\" style=\"clear: both;\">
<tr>
<td class=\"thead\" colspan=\"2\">
	<div style=\"float: right;\">
		<span class=\"smalltext\">Первое сообщение темы</span>
	</div>
</td></tr>
<tr>
<td class=\"tcat\" width=\"15%\"><span class=\"smalltext\"><strong>Автор</strong></span></td>
<td class=\"tcat\" width=\"85%\"><span class=\"smalltext\"><strong>Сообщение</strong></span></td>
</tr>\$posts</table><br />",
		"sid"		=> -1,
		"version"	=> 120,
		"status"	=> '',
		"dateline"	=> '1134703640',
	);
	$db->insert_query("templates", $fp_template);
	find_replace_templatesets("showthread", '#{\$header}(\r?)\n#', "{\$header}\n{\$fpost2}\n");
}
function show_first_post_deactivate()
{
	require MYBB_ROOT.'/inc/adminfunctions_templates.php';
	global $db;
	
	$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='global_first_post'");
	find_replace_templatesets("showthread", '#{\$fpost2}(\r?)\n#', "", 0);
}
function show_first_post()
{
	global $db,$mybb,$templates,$fpost2,$firstpostcontent;
	if(isset($mybb->input['page']) && $mybb->input['page'] != 1) {
	if(!function_exists('build_postbit')) {
  require_once MYBB_ROOT.'/inc/functions_post.php';
  }
  $pfirst = true;
		$posts = '';
		$query = $db->query("
			SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername
			FROM ".TABLE_PREFIX."posts p
			LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
			LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
			LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
			WHERE p.tid = '".$mybb->input['tid']."'
			ORDER BY p.dateline ASC
			LIMIT 0,1
		");
		while($post = $db->fetch_array($query))
		{
			$post['visible'] = 1;
			$posts .= build_postbit($post);
			$post = '';
			$pfirst = false;
		}
		eval("\$fpost2 = \"".$templates->get('global_first_post')."\";");
}
}
?>
change all occurances of require to require_once in that plugin file ...
ok, I did it
Quote: Line 24: require_once MYBB_ROOT.'/inc/adminfunctions_templates.php';
Line 49: require_once MYBB_ROOT.'/inc/adminfunctions_templates.php';
Line 60: require_once MYBB_ROOT.'/inc/functions_post.php';
that didn't help Confused

[attachment=24787]
yep I always use Notepad++ and saving files fithout BOM
^ you have utf-8 encoding for the file ; save in ANSI & use ...
Oh shooot, the file was in utf-8 but with BOM, don't kill me guys Blush
now it works!