php code error
Moderator: General Moderators
php code error
hi friends back again,
im running a php script on my html page to show latest forum topics in a sidebar, im getting errors can some php wizard help me out here cause im new to this stuff here is the error. im just testing a new webpage im trying to build im also new to webdesign aswell so im in at the deep end. i need some sugestions
kind regards jj
[phpBB Debug] PHP Notice: in file /includes/session.php on line 990: Cannot modify header information - headers already sent by (output started at /home/nimccnet/public_html/index22.html:8)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 990: Cannot modify header information - headers already sent by (output started at /home/nimccnet/public_html/index22.html:8)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 990: Cannot modify header information - headers already sent by (output started at /home/nimccnet/public_html/index22.html:8)
HERE IS THE SCRIPT
<?
define('IN_PHPBB', true);
$phpbb_root_path = './nimccforum/'; // Path to phpbb folder
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
// Grab user preferences
$user->setup();
?>
<?
/*** phpBB3 - Last Active Topics System ***/
//Show last x topics
define('TOPICS_LIMIT',10);
// Create arrays
$topics = array();
// Get forums that current user has read rights to.
$forums = array_unique(array_keys($auth->acl_getf('f_read', true)));
// Get active topics.
$sql="SELECT *
FROM " . TOPICS_TABLE . "
WHERE topic_approved = '1' AND " . $db->sql_in_set('forum_id', $forums) . "
ORDER BY topic_last_post_time DESC";
$result = $db->sql_query_limit($sql,TOPICS_LIMIT);
while ($r = $db->sql_fetchrow($result))
{
$topics[] = $r;
}
$db->sql_freeresult($result);
?>
<div>
<?
foreach($topics as $t)
{
// Get folder img, topic status/type related information
$topic_tracking_info = get_complete_topic_tracking($t['forum_id'], $t['topic_id']);
$unread_topic = (isset($topic_tracking_info[$t['topic_id']]) && $t['topic_last_post_time'] > $topic_tracking_info[$t['topic_id']]) ? true : false;
$folder_img = $folder_alt = $topic_type = '';
topic_status($t, $t['topic_replies'], $unread_topic, $folder_img, $folder_alt, $topic_type);
// output the link
?>
<img style="vertical-align: text-bottom" src="<?=$user->img($folder_img, $folder_alt, false, '', 'src');?>" title="<?=$user->lang[$folder_alt];?>" alt="<?=$user->lang[$folder_alt];?>" />
<a href="<?=$phpbb_root_path . 'viewtopic.php?f=' . $t['forum_id'] . '&t=' . $t['topic_id'] . '&p=' . $t['topic_last_post_id'] . '#p' . $t['topic_last_post_id'];?>"><?=html_entity_decode($t['topic_title']);?></a><br />
<?
}
?>
</div>
im running a php script on my html page to show latest forum topics in a sidebar, im getting errors can some php wizard help me out here cause im new to this stuff here is the error. im just testing a new webpage im trying to build im also new to webdesign aswell so im in at the deep end. i need some sugestions
kind regards jj
[phpBB Debug] PHP Notice: in file /includes/session.php on line 990: Cannot modify header information - headers already sent by (output started at /home/nimccnet/public_html/index22.html:8)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 990: Cannot modify header information - headers already sent by (output started at /home/nimccnet/public_html/index22.html:8)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 990: Cannot modify header information - headers already sent by (output started at /home/nimccnet/public_html/index22.html:8)
HERE IS THE SCRIPT
<?
define('IN_PHPBB', true);
$phpbb_root_path = './nimccforum/'; // Path to phpbb folder
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
// Grab user preferences
$user->setup();
?>
<?
/*** phpBB3 - Last Active Topics System ***/
//Show last x topics
define('TOPICS_LIMIT',10);
// Create arrays
$topics = array();
// Get forums that current user has read rights to.
$forums = array_unique(array_keys($auth->acl_getf('f_read', true)));
// Get active topics.
$sql="SELECT *
FROM " . TOPICS_TABLE . "
WHERE topic_approved = '1' AND " . $db->sql_in_set('forum_id', $forums) . "
ORDER BY topic_last_post_time DESC";
$result = $db->sql_query_limit($sql,TOPICS_LIMIT);
while ($r = $db->sql_fetchrow($result))
{
$topics[] = $r;
}
$db->sql_freeresult($result);
?>
<div>
<?
foreach($topics as $t)
{
// Get folder img, topic status/type related information
$topic_tracking_info = get_complete_topic_tracking($t['forum_id'], $t['topic_id']);
$unread_topic = (isset($topic_tracking_info[$t['topic_id']]) && $t['topic_last_post_time'] > $topic_tracking_info[$t['topic_id']]) ? true : false;
$folder_img = $folder_alt = $topic_type = '';
topic_status($t, $t['topic_replies'], $unread_topic, $folder_img, $folder_alt, $topic_type);
// output the link
?>
<img style="vertical-align: text-bottom" src="<?=$user->img($folder_img, $folder_alt, false, '', 'src');?>" title="<?=$user->lang[$folder_alt];?>" alt="<?=$user->lang[$folder_alt];?>" />
<a href="<?=$phpbb_root_path . 'viewtopic.php?f=' . $t['forum_id'] . '&t=' . $t['topic_id'] . '&p=' . $t['topic_last_post_id'] . '#p' . $t['topic_last_post_id'];?>"><?=html_entity_decode($t['topic_title']);?></a><br />
<?
}
?>
</div>
Last edited by jacen100 on Fri Aug 21, 2009 4:33 pm, edited 5 times in total.
Re: php code error
You can't call header() or session_start() if you've already outputted something.
Code: Select all
// wrong
echo "something";
header("Name: value");
// right
header("Name: value");
echo "something";Re: php code error
hi thx for fast reply can u edit the script for me? is that possible 
Re: php code error
He's told you what to do, can't you edit it yourself? It'll take what, like 30 seconds?
Re: php code error
maby im blind but i cant see the part i need to alter, also i dident write the code im not a writer i havent the first clue about php im tryin g to learn tho that is why i joind this forum to try get some help 
Re: php code error
Well, I can't see the problem from the code you've posted...
Try looking at the source in your browser. Is there anything before the error messages?
Try looking at the source in your browser. Is there anything before the error messages?
Re: php code error
here is the webpage im testing atm that im getting the error on can i see it?
http://www.nimcc.net/index22.html
http://www.nimcc.net/index22.html
Re: php code error
I can't connect to your server
Too busy or temporarily unavailable apparently.
Too busy or temporarily unavailable apparently.
Re: php code error
should be ok now 
Re: php code error
You've got about three quarters of your page before the error. You need to send headers before output!!!!!!!
Re: php code error
can u explaine in anymore detail, thx for your info and help by the way ,
is there a part of the code to go at top of page do u mean? i have the whole php code uploaded to my server a directory below the forum, then i have added the php include command on the html page were i want the posts to appear, do i have to add any of that php code to the html page also?
is there a part of the code to go at top of page do u mean? i have the whole php code uploaded to my server a directory below the forum, then i have added the php include command on the html page were i want the posts to appear, do i have to add any of that php code to the html page also?
Re: php code error
YOU HAVE TO SEND HEADERS BEFORE ANY OUTPUT.
Stuff like session_start(), header() and setcookie() must go before echo or print.
Stuff like session_start(), header() and setcookie() must go before echo or print.
Re: php code error
i think maby im getting somewere im using a different code i dont think its showing the output error now but when i click the post for some reason its pointing to http://nimcc.net/phpBB3viewtopic.php?f= ... p=969#p969 and it should be pointing to http://nimcc.net/nimccforum/viewtopic.php?f=2&t=189 im trying to find were in the code i should alter have u any idea?
thx for your hlp so far here is the code im using
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './nimccforum/'; // Path to phpbb folder
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
//$user->session_begin();
//$auth->acl($user->data);
//$user->setup();
// Number of posts and grabbing permissions
// Pocet prspevku pro zobrazen a oprvnen
$topic_limit = request_var('topic_limit', 5);
$forums = array_unique(array_keys($auth->acl_getf('f_read', true))); //ignored in sql statement to include all topics despite permissions
// Select the last topics based on user permissions
/* $sql = 'SELECT p.post_id, p.topic_id, p.forum_id, p.post_subject, p.post_time, u.username
FROM ' . POSTS_TABLE . ' p , ' . USERS_TABLE . ' u
WHERE post_approved = 1
AND ' . $db->sql_in_set('forum_id', $forums) . '
AND u.user_id = p.poster_id
ORDER BY post_time DESC
LIMIT 0,' . $topic_limit;
$result = $db->sql_query($sql); */
// Select the last topics ignoring permissions
// Vybrat posledn tmata ke kterm mme oprvnen
$sql = 'SELECT p.post_id, p.topic_id, p.forum_id, p.post_subject, p.post_time, u.username
FROM ' . POSTS_TABLE . ' p , ' . USERS_TABLE . ' u
WHERE post_approved = 1
AND u.user_id = p.poster_id
ORDER BY post_time DESC
LIMIT 0,' . $topic_limit;
$result = $db->sql_query($sql);
// Proper header since output not buffered
// Poslat hlavicky pro sprvn kdovn, protoe vpis obsahu je postupn
// header('Content-Type: text/html; charset=utf-8');
// Now let's output the content
// A ted vypsat obsah
// echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- ... dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Last Topics</title></head><body><div id="post_content"><strong>Last Topics:</strong><br/><ul>';
while ($row = $db->sql_fetchrow($result))
{
$url = generate_board_url() . "viewtopic.{$phpEx}?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}"; //
//old line $url = generate_board_url() . "viewtopic.{$phpEx}?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}";
echo '<tr><td colspan=\"2\"><a target="_blank" href="' . $url . '">' . $row['post_subject'] . '</a>, ' . ucwords($row['username']) . ', ' . date("d/m Hi",$row['post_time']).'hrs</td></tr>';
}
echo '</div></body></html>';
?>
thx for your hlp so far here is the code im using
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './nimccforum/'; // Path to phpbb folder
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
//$user->session_begin();
//$auth->acl($user->data);
//$user->setup();
// Number of posts and grabbing permissions
// Pocet prspevku pro zobrazen a oprvnen
$topic_limit = request_var('topic_limit', 5);
$forums = array_unique(array_keys($auth->acl_getf('f_read', true))); //ignored in sql statement to include all topics despite permissions
// Select the last topics based on user permissions
/* $sql = 'SELECT p.post_id, p.topic_id, p.forum_id, p.post_subject, p.post_time, u.username
FROM ' . POSTS_TABLE . ' p , ' . USERS_TABLE . ' u
WHERE post_approved = 1
AND ' . $db->sql_in_set('forum_id', $forums) . '
AND u.user_id = p.poster_id
ORDER BY post_time DESC
LIMIT 0,' . $topic_limit;
$result = $db->sql_query($sql); */
// Select the last topics ignoring permissions
// Vybrat posledn tmata ke kterm mme oprvnen
$sql = 'SELECT p.post_id, p.topic_id, p.forum_id, p.post_subject, p.post_time, u.username
FROM ' . POSTS_TABLE . ' p , ' . USERS_TABLE . ' u
WHERE post_approved = 1
AND u.user_id = p.poster_id
ORDER BY post_time DESC
LIMIT 0,' . $topic_limit;
$result = $db->sql_query($sql);
// Proper header since output not buffered
// Poslat hlavicky pro sprvn kdovn, protoe vpis obsahu je postupn
// header('Content-Type: text/html; charset=utf-8');
// Now let's output the content
// A ted vypsat obsah
// echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- ... dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Last Topics</title></head><body><div id="post_content"><strong>Last Topics:</strong><br/><ul>';
while ($row = $db->sql_fetchrow($result))
{
$url = generate_board_url() . "viewtopic.{$phpEx}?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}"; //
//old line $url = generate_board_url() . "viewtopic.{$phpEx}?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}";
echo '<tr><td colspan=\"2\"><a target="_blank" href="' . $url . '">' . $row['post_subject'] . '</a>, ' . ucwords($row['username']) . ', ' . date("d/m Hi",$row['post_time']).'hrs</td></tr>';
}
echo '</div></body></html>';
?>
Re: php code error
I'm no phpbb expert, but I'd imagine it's something to do with this line:
Code: Select all
$url = generate_board_url() . "viewtopic.{$phpEx}?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}";Re: php code error
me either but i tried adding this
$url = generate_board_url() . "/nimccforum/viewtopic.{$phpEx}?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}";
then when i click the post it takes me to
http://nimcc.net/phpBB3/nimccforum/view ... p=969#p969
so i cant understand were its gettin the /phpbb3/ directory from
$url = generate_board_url() . "/nimccforum/viewtopic.{$phpEx}?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}";
then when i click the post it takes me to
http://nimcc.net/phpBB3/nimccforum/view ... p=969#p969
so i cant understand were its gettin the /phpbb3/ directory from