Jump to content

Archived

This topic is now archived and is closed to further replies.

Deathwillow

Simple News script using phpbb3 help.

Recommended Posts

So I've got a simple news script that pulls the last 5 posts in a specific phpbb3 forum but I'm getting errors on the front page whenever they don't at least open the forums before. There errors:

 

To narrow it down a little more for everyone, When they visit the home page( http://im.deathwillow.com ) before visiting the forums they receive the following errors.  Once they have at least visited, not requiring a log in, the forums ( http://im.deathwillow.com/forums ) the errors disappear.  Any ideas?

 

[phpBB Debug] PHP Notice: in file /includes/session.php on line 1024: Cannot modify header information - headers already sent by (output started at /hermes/web03/b36/pow.deathwillow21/IM/index.php:
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1024: Cannot modify header information - headers already sent by (output started at /hermes/web03/b36/pow.deathwillow21/IM/index.php:
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1024: Cannot modify header information - headers already sent by (output started at /hermes/web03/b36/pow.deathwillow21/IM/index.php:

 

 

The script:

 

<?php
define('FORUM_ID', 6);                    // Forum ID to get data from
define('POST_LIMIT', 5);                  // How many to get
define('PHPBB_ROOT_PATH', './forums/');   // Path to phpBB (including trailing /)

define('PRINT_TO_SCREEN', true);         
         // If set to true, it will print the posts out
         // If set to false it will create an array $news[] with all the following info
         //
         //   'topic_id'         eg. 119
         //   
         //   'topic_time'      eg. 06 June, 07 (uses board default)
         //   'topic_replies'      eg. 26
         //   
         //   'username'         eg. chAos
         //   'topic_title'      eg. "News Post"
         //   
         //   'post_text'         eg. just the text (formatted w/ smilies, bbcode, etc)

define('IN_PHPBB', true);
$phpbb_root_path = PHPBB_ROOT_PATH;
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);

// Start session management
$user->session_begin(false);
$auth->acl($user->data);

// Grab user preferences
$user->setup();

$query = 
"SELECT u.user_id, u.username, t.topic_title, t.topic_poster, t.forum_id, t.topic_id, t.topic_time, t.topic_replies, t.topic_first_post_id, p.poster_id, p.topic_id, p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid 
FROM ".USERS_TABLE." u, ".TOPICS_TABLE." t, ".POSTS_TABLE." p 
WHERE u.user_id = t.topic_poster 
AND u.user_id = p.poster_id 
AND t.topic_id = p.topic_id 
AND p.post_id = t.topic_first_post_id 
AND t.forum_id = ".FORUM_ID." 
ORDER BY t.topic_time DESC";

$result = $db->sql_query_limit($query, POST_LIMIT);
$posts = array();
$news = array();
$bbcode_bitfield = '';
$message = '';
$poster_id = 0;

while ($r = $db->sql_fetchrow($result))
{
   $posts[] = array(
         'topic_id' => $r['topic_id'],
         'topic_time' => $r['topic_time'], 
         'username' => $r['username'], 
         'topic_title' => $r['topic_title'], 
         'post_text' => $r['post_text'],
         'bbcode_uid' => $r['bbcode_uid'],
         'bbcode_bitfield' => $r['bbcode_bitfield'],
         'topic_replies' => $r['topic_replies'],
         );
   $bbcode_bitfield = $bbcode_bitfield | base64_decode($r['bbcode_bitfield']);
}


// Instantiate BBCode
if ($bbcode_bitfield !== '')
{
   $bbcode = new bbcode(base64_encode($bbcode_bitfield));
}

// Output the posts
foreach($posts as $m)
{
   $poster_id = $m['user_id'];
   
   $message = $m['post_text'];
   if($m['bbcode_bitfield'])
   {
      $bbcode->bbcode_second_pass($message, $m['bbcode_uid'], $m['bbcode_bitfield']);
   }

   $message = str_replace("\n", '<br />', $message);
   $message = smiley_text($message);

   $comment = ($m['topic_replies']==1) ? 'comment' : 'comments';
   
   if( PRINT_TO_SCREEN )
   {
      /* Output is in the following format
       *
       * <h3>Thread Title</h3>
       ^ <h4 class="postinfo">date // 5 comments // poster</h4>
       * <p>First post test</p>
       * 
       */
  
  echo "<div class=\"newsPost\">
  			<h1><span class=\"topic\"><a href=\"".PHPBB_ROOT_PATH."viewtopic.php?f=".FORUM_ID."&t={$m['topic_id']}\">{$m['topic_title']}</a></span></h1>
			<p>{$message}</p>
			<div class=\"newsPost_footer\">
				<span class=\"newsPost_comments\">Comments: <a href=\"".PHPBB_ROOT_PATH."viewtopic.php?f=".FORUM_ID."&t={$m['topic_id']}\">{$m['topic_replies']}</a></span><span class=\"newsPost_author\">Posted by <i><font color=\"#CCCCCC\">{$m['username']} </font>on " . $user->format_date($m['topic_time']) . "</i></span>
			</div>
		</div>";
   }
   else
   { 	
      $news[] = array(
            'topic_id' => $m['topic_id'], // eg: 119
            
            'topic_time' => $user->format_date($m['topic_time']), // eg: 06 June, 07 (uses board default)
            'topic_replies' => $m['topic_replies'], // eg: 26
            
            'username' => $m['username'], // eg: chAos
            'topic_title' => $m['topic_title'], // eg: "News Post"
            
            'post_text' => $message, // just the text         
            );
   }
   
   unset($message,$poster_id);
}

?>

Share this post


Link to post
Share on other sites

I guess the simplest way I can think to put it is, some physical (metaphorically speaking) piece of html, text, or information is being output to the browser prior to that script running. Or another session is being called out and started prior to this particular scripts running.

 

Seeing as you mention its login based. Chances are there's sessions somewhere being implemented in before that script runs.

 

sessions() have to come before headers and there can only be one session running at the start of the script to the end of the scripts rendering, headers have to come before any kind of codes output.. ie print or echo for example. or even before the

<html>

outputs..

 

I see in your script its calling to a session of some sort. So maybe a work around to that statement is required

Share this post


Link to post
Share on other sites

Any ideas?

 

^^^ Yes, simply read the error messages, they tell you where the output is occurring at that is preventing the header from working. Something at or up to line 8 in index.php is sending output to the browser -

 

output started at /hermes/web03/b36/pow.deathwillow21/IM/index.php:8)

 

You would need to find what is causing that output to be sent before a header statement and eliminate it, assuming it was unintended output or correct the code so that any logic that sends a header is located before you produce and send any output to the browser.

Share this post


Link to post
Share on other sites

I'm not exactly sure where in the index file this could be happening, here's what it is:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII" />
<title>Insinuo Matris</title>
    <link href="main.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="jQuery/jquery.1.4.3.js"></script>
    <script type="text/javascript" src="http://static.wowhead.com/widgets/power.js"></script>
</head>

<body>
    <div id="page">
        <div id="topImage">
            </p> </P>
        </div>
	<div id="navBar">
            <div class="navBar">
                <ul>
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="/forums">Forums</a></li>
                    <li><a href="/roster">Roster</a></li>
                    <li><a href="/media">Videos</a></li>
                    <li><a href="/loot">Loot</a></li>
                    <li><a href="/downloads">Downloads</a></li>
                </ul>
            </div> 
        </div>
        <div id="content">
            <div id="contentArea">
                <div id="breadCrumb"></div>
                <div id="contentLeft">
                	<?php include('news.php'); ?>
                </div>
                <div id="contentRight">
                	<div class="contentRightSetup">
                    	<h1><span class="topic">Currently Recruiting:</span></h1>
                        <ul class="recruitmentList">
                        	<?php include('recruitment.php'); ?>
                        </ul>
                    </div>   
                    <div class="spacer"></div>
                    <div class="contentRightSetup">
                    	<h1><span class="topic">Recent Loot:</span></h1>
                        <p>Loot to be added later.</p>
                    </div> 
				<div class="spacer"></div>
                    <div class="contentRightSetup">
                    	<h1><span class="topic">Recent Blue Posts:</span></h1>
                        <ul>
                        	<span class="blueFeed">
                        		<?php include('bluePosts.php'); ?>
                            </span>
                        </ul>
                    </div>               
                </div>
            </div>
        </div>
    </div>
</body>
</html>

 

 

:confused:

Share this post


Link to post
Share on other sites

ANY output to browser before starting a session will cause that error. that includes HTML.

Share this post


Link to post
Share on other sites

So should I place:

<?php include('news.php'); ?>

 

at the VERY beginning of index.php and use the array function where I need to display the information.

 

 

Example of what I mean would be:

 

<?php include('news.php'); ?>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII" />
<title>Insinuo Matris</title>
    <link href="main.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="jQuery/jquery.1.4.3.js"></script>
    <script type="text/javascript" src="http://static.wowhead.com/widgets/power.js"></script>
</head>

<body>
    <div id="page">
        <div id="topImage">
            </p> </P>
        </div>
	<div id="navBar">
            <div class="navBar">
                <ul>
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="/forums">Forums</a></li>
                    <li><a href="/roster">Roster</a></li>
                    <li><a href="/media">Videos</a></li>
                    <li><a href="/loot">Loot</a></li>
                    <li><a href="/downloads">Downloads</a></li>
                </ul>
            </div> 
        </div>
        <div id="content">
            <div id="contentArea">
                <div id="breadCrumb"></div>
                <div id="contentLeft">
                	** PHP LOOP HERE RECALLING THE ARRAY FROM NEWS.PHP **
                </div>
                <div id="contentRight">
                	<div class="contentRightSetup">
                    	<h1><span class="topic">Currently Recruiting:</span></h1>
                        <ul class="recruitmentList">
                        	<?php include('recruitment.php'); ?>
                        </ul>
                    </div>   
                    <div class="spacer"></div>
                    <div class="contentRightSetup">
                    	<h1><span class="topic">Recent Loot:</span></h1>
                        <p>Loot to be added later.</p>
                    </div> 
				<div class="spacer"></div>
                    <div class="contentRightSetup">
                    	<h1><span class="topic">Recent Blue Posts:</span></h1>
                        <ul>
                        	<span class="blueFeed">
                        		<?php include('bluePosts.php'); ?>
                            </span>
                        </ul>
                    </div>               
                </div>
            </div>
        </div>
    </div>
</body>
</html>

 

 

If i'm understanding you guys right, that should correct it right?

Share this post


Link to post
Share on other sites

Actually I just went ahead and tried the above and it all seems to work like a charm now, for reference here's the final code. :)

 

<?php include('news.php'); ?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII" />
<title>Insinuo Matris</title>
    <link href="main.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="jQuery/jquery.1.4.3.js"></script>
    <script type="text/javascript" src="http://static.wowhead.com/widgets/power.js"></script>
</head>

<body>
    <div id="page">
        <div id="topImage">
            </p> </P>
        </div>
	<div id="navBar">
            <div class="navBar">
                <ul>
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="/forums">Forums</a></li>
                    <li><a href="/roster">Roster</a></li>
                    <li><a href="/media">Videos</a></li>
                    <li><a href="/loot">Loot</a></li>
                    <li><a href="/downloads">Downloads</a></li>
                </ul>
            </div> 
        </div>
        <div id="content">
            <div id="contentArea">
                <div id="breadCrumb"></div>
                <div id="contentLeft">
                	<?php
					foreach($news as $n) {
						echo "<div class=\"newsPost\">
								  <h1><span class=\"topic\"><a href=\"".PHPBB_ROOT_PATH."viewtopic.php?f=".FORUM_ID."&t={$n['topic_id']}\">{$n['topic_title']}</a></span></h1>
								  <p>{$n['post_text']}</p>
								  <div class=\"newsPost_footer\">
								      <span class=\"newsPost_comments\">Comments: <a href=\"".PHPBB_ROOT_PATH."viewtopic.php?f=".FORUM_ID."&t={$n['topic_id']}\">{$n['topic_replies']}</a></span><span class=\"newsPost_author\">Posted by <i><font color=\"#CCCCCC\">{$n['username']} </font>on " . $user->format_date($n['topic_time']) . "</i></span>
							      </div>
						      </div>";
					}
				?>
                </div>
                <div id="contentRight">
                	<div class="contentRightSetup">
                    	<h1><span class="topic">Currently Recruiting:</span></h1>
                        <ul class="recruitmentList">
                        	<?php include('recruitment.php'); ?>
                        </ul>
                    </div>   
                    <div class="spacer"></div>
                    <div class="contentRightSetup">
                    	<h1><span class="topic">Recent Loot:</span></h1>
                        <p>Loot to be added later.</p>
                    </div> 
				<div class="spacer"></div>
                    <div class="contentRightSetup">
                    	<h1><span class="topic">Recent Blue Posts:</span></h1>
                        <ul>
                        	<span class="blueFeed">
                        		<?php include('bluePosts.php'); ?>
                            </span>
                        </ul>
                    </div>               
                </div>
            </div>
        </div>
    </div>
</body>
</html>

 

thanks to everyone who replied and help me with this issue, it's been plaguing me for a while. :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.