Page 1 of 1

phpBB help (login from non-phpbb pages)

Posted: Mon Aug 18, 2003 8:40 am
by eclips
Im using this code on my non-phpbb pages. And I am wondering how to get it to redirect back to the non-phpbb page they logged in from or back to my index page.


I also get this error. How do I fix it, I'm new to php.

Warning: Cannot modify header information - headers already sent by (output started at c:\program files\apache group\apache\htdocs\index.php:10) in c:\program files\apache group\apache\htdocs\phpbb2\includes\sessions.php on line 182

Warning: Cannot modify header information - headers already sent by (output started at c:\program files\apache group\apache\htdocs\index.php:10) in c:\program files\apache group\apache\htdocs\phpbb2\includes\sessions.php on line 183


Thanks for any responses. :D

Code: Select all

<?php 

//Dynamic phpBB template by AJ Quick 
//www.ajquick.com 

define('IN_PHPBB', true); 

$site_root_path = ''; //<-- Modify 
$phpbb_root_path2 = 'phpbb2/'; //<-- Modify 
$phpbb_root_path = $site_root_path . $phpbb_root_path2; 
include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.php'); 

$userdata = session_pagestart($user_ip, PAGE_INDEX); 
init_userprefs($userdata); 


//Who Is Online 
//By Acid 
//http://www.phpbbhacks.com/viewhack.php?id=201 
$user_forum_sql = ( !empty($forum_id) ) ? "AND ( u.user_session_page = $forum_id 
   OR s.session_page = $forum_id)" : ""; 

$sql = "SELECT u.username, u.user_id, u.user_allow_viewonline, u.user_level, s.session_logged_in, s.session_ip 
   FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s 
   WHERE u.user_id = s.session_user_id 
      AND ( s.session_time >= ".( time() - 300 ) . " 
         OR u.user_session_time >= " . ( time() - 300 ) . " ) 
      $user_forum_sql 
   ORDER BY u.username ASC"; 
$result = $db->sql_query($sql); 
if(!$result) 
{ 
   message_die(GENERAL_ERROR, "Couldn't obtain user/online information.", "", __LINE__, __FILE__, $sql); 
} 

$userlist_ary = array(); 
$userlist_visible = array(); 

$logged_visible_online = 0; 
$logged_hidden_online = 0; 
$guests_online = 0; 
$online_userlist = ""; 

$prev_user_id = 0; 
$prev_session_ip = 0; 

while( $row = $db->sql_fetchrow($result) ) 
{ 
   // User is logged in and therefor not a guest 
   if( $row['session_logged_in'] ) 
   { 
      // Skip multiple sessions for one user 
      if( $row['user_id'] != $prev_user_id ) 
      { 
         $style_color = ""; 
         if( $row['user_level'] == ADMIN ) 
         { 
            $row['username'] = '<b>' . $row['username'] . '</b>'; 
            $style_color = 'style="color:#' . $theme['fontcolor3'] . '"'; 
         } 
         else if( $row['user_level'] == MOD ) 
         { 
            $row['username'] = '<b>' . $row['username'] . '</b>'; 
            $style_color = 'style="color:#' . $theme['fontcolor2'] . '"'; 
         } 

         if( $row['user_allow_viewonline'] ) 
         { 
            $user_online_link = '<a href="' . append_sid($phpbb_root_path2."profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']) . '"' . $style_color .'>' . $row['username'] . '</a>'; 
            $logged_visible_online++; 
         } 
         else 
         { 
            $user_online_link = '<a href="' . append_sid($phpbb_root_path2."profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']) . '"' . $style_color .'><i>' . $row['username'] . '</i></a>'; 
            $logged_hidden_online++; 
         } 
          
         if( $row['user_allow_viewonline'] || $userdata['user_level'] == ADMIN ) 
         { 
            $online_userlist .= ( $online_userlist != "" ) ? ", " . $user_online_link : $user_online_link; 
         } 
      } 
   } 
   else 
   { 
         if( $row['session_ip'] != $prev_session_ip ){ 
                   $guests_online++; 
         }  
   } 

   $prev_user_id = $row['user_id']; 
   $prev_session_ip = $row['session_ip']; 
} 

if( empty($online_userlist) ) 
{ 
   $online_userlist = $lang['None']; 
} 
$online_userlist = ( ( isset($forum_id) ) ? $lang['Browsing_forum'] : $lang['Registered_users'] ) . " " . $online_userlist; 

$total_online_users = $logged_visible_online + $logged_hidden_online + $guests_online; 

if($total_online_users > $board_config['record_online_users']) 
{ 
   $sql = "UPDATE " . CONFIG_TABLE . " 
      SET config_value = '$total_online_users' 
      WHERE config_name = 'record_online_users'"; 
   if( !$result = $db->sql_query($sql) ) 
   { 
      message_die(GENERAL_ERROR, "Couldn't update online user record (nr of users)", "", __LINE__, __FILE__, $sql); 
   } 

   $sql = "UPDATE " . CONFIG_TABLE . " 
      SET config_value = '" . time() . "' 
      WHERE config_name = 'record_online_date'"; 
   if( !$result = $db->sql_query($sql) ) 
   { 
      message_die(GENERAL_ERROR, "Couldn't update online user record (date)", "", __LINE__, __FILE__, $sql); 
   } 

   $board_config['record_online_users'] = $total_online_users; 
   $board_config['record_online_date'] = time(); 
} 

if( $total_online_users == 0 ) 
{ 
   $l_t_user_s = $lang['Online_users_zero_total']; 
} 
else if( $total_online_users == 1 ) 
{ 
   $l_t_user_s = $lang['Online_user_total']; 
} 
else 
{ 
   $l_t_user_s = $lang['Online_users_total']; 
} 

if( $logged_visible_online == 0 ) 
{ 
   $l_r_user_s = $lang['Reg_users_zero_total']; 
} 
else if( $logged_visible_online == 1 ) 
{ 
   $l_r_user_s = $lang['Reg_user_total']; 
} 
else 
{ 
   $l_r_user_s = $lang['Reg_users_total']; 
} 

if( $logged_hidden_online == 0 ) 
{ 
   $l_h_user_s = $lang['Hidden_users_zero_total']; 
} 
else if( $logged_hidden_online == 1 ) 
{ 
   $l_h_user_s = $lang['Hidden_user_total']; 
} 
else 
{ 
   $l_h_user_s = $lang['Hidden_users_total']; 
} 

if( $guests_online == 0 ) 
{ 
   $l_g_user_s = $lang['Guest_users_zero_total']; 
} 
else if( $guests_online == 1 ) 
{ 
   $l_g_user_s = $lang['Guest_user_total']; 
} 
else 
{ 
   $l_g_user_s = $lang['Guest_users_total']; 
} 

$l_online_users = sprintf($l_t_user_s, $total_online_users); 
$l_online_users .= sprintf($l_r_user_s, $logged_visible_online); 
$l_online_users .= sprintf($l_h_user_s, $logged_hidden_online); 
$l_online_users .= sprintf($l_g_user_s, $guests_online); 

$onlinet="$l_online_users<br>$online_userlist<br>"; 


//Private Message Throughout Site 
//By AJ Quick 

if($userdata['session_logged_in']){//logged in 

if ( $userdata['user_new_privmsg'] )//private messages 
   { 
      $l_message_new = ( $userdata['user_new_privmsg'] == 1 ) ? $lang['New_pm'] : $lang['New_pms']; 
      $l_privmsgs_text = sprintf($l_message_new, $userdata['user_new_privmsg']); 

      if ( $userdata['user_last_privmsg'] > $userdata['user_lastvisit'] ) 
      { 
         $sql = "UPDATE " . USERS_TABLE . " 
            SET user_last_privmsg = " . $userdata['user_lastvisit'] . " 
            WHERE user_id = " . $userdata['user_id']; 
         if ( !$db->sql_query($sql) ) 
         { 
            message_die(GENERAL_ERROR, 'Could not update private message new/read time for user', '', __LINE__, __FILE__, $sql); 
         } 

         $s_privmsg_new = 1; 
         $icon_pm = $images['pm_new_msg']; 
      } 
      else 
      { 
         $s_privmsg_new = 0; 
         $icon_pm = $images['pm_no_new_msg']; 
      } 
   } 
   else 
   { 
      $l_privmsgs_text = $lang['No_new_pm']; 

      $s_privmsg_new = 0; 
      $icon_pm = $images['pm_no_new_msg']; 
   } 

   if ( $userdata['user_unread_privmsg'] ) 
   { 
      $l_message_unread = ( $userdata['user_unread_privmsg'] == 1 ) ? $lang['Unread_pm'] : $lang['Unread_pms']; 
      $l_privmsgs_text_unread = sprintf($l_message_unread, $userdata['user_unread_privmsg']); 
   } 
   else 
   { 
      $l_privmsgs_text_unread = $lang['No_unread_pm']; 
   } 

}// User Logged In 

//REMOVE THIS IF NOT INSTALLED 

//Birthdays Announcements 
//Originally By Niels Chr 
//Heavily Changed By AJ Quick 

if($userdata['session_logged_in']){//logged in 


   $year=create_date('Y', time(), $board_config['default_timezone']); 
   if ($userdata['user_birthday']!=999999 && $board_config['birthday_greeting'] && create_date('Ymd', time(), $board_config['default_timezone']) >= $userdata['user_next_birthday_greeting'].realdate ('md',$userdata['user_birthday'])) 
      { 
         $sql = "UPDATE " . USERS_TABLE . " 
            SET user_next_birthday_greeting = " . ($year+1) . " 
            WHERE user_id = " . $userdata['user_id']; 
         if( !$status = $db->sql_query($sql) ) 
         { 
            message_die(GENERAL_ERROR, "Could not update next_birthday_greeting for user.", "", __LINE__, __FILE__, $sql); 
         } 
      $db->sql_freeresult($status); 
         $greeting_flag=1; 
      } else $greeting_flag=0;//Sorry user shall not have a greeting this year 

}// User Logged In 

?> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
</head> 
<title>Site Name</title> 
<?php 
if ( !empty($userdata['user_popup_pm']) ){ 
?> 
<script language="Javascript" type="text/javascript"> 
<!-- 
   if (<?php echo $s_privmsg_new ?>) 
   { 
      window.open('<?php echo "$phpbb_root_pathprivmsg.".$phpEx."?mode=newpm" ?>', '_phpbbprivmsg', 'HEIGHT=225,resizable=yes,WIDTH=400');; 
   } 
//--> 
</script> 
<?php 
} 

//REMOVE THIS IF BIRTHDAYS NOT INSTALLED 
if(date('Y') == $userdata['user_next_birthday_greeting']){ 
?> 
<script language="Javascript" type="text/javascript"> 
<!-- 
   var greeting_flag = <?php echo $greeting_flag ?>; 

   if( greeting_flag ) 
   { 
      window.open('<?php echo $phpbb_root_path2 ?>privmsg.php?mode=birthday', '_phpbbprivmsg', 'HEIGHT=225,resizable=yes,WIDTH=400'); 
   } 
//--> 
</script> 
<?php 
} 
?> 
<body> 

<?php 
if($userdata['session_logged_in']){ 
?> 
   You Are Logged In,<br> 
   <?php echo $userdata[username] ?> 
   <a href="<?php echo $phpbb_root_path2 ?>profile.php?mode=editprofile">Profile</a> | <a href="/phpbb2/login.php?logout=true">Logout</a><br> 
   <a href="<?php echo $phpbb_root_path2 ?>privmsg.php?folder=inbox"><?php echo $l_privmsgs_text ?></a><br><br> 

   <?php echo $onlinet ?> 

<?php 
}else{ 
?> 
   <p align="center"><form action="phpbb2/login.php" method="post"> 
<table width="100%" cellspacing="2" cellpadding="2" border="0"> 
<tr> 
   <td class="maintitle" valign="top"> 
    <p align="center"><b><font face="Century Gothic">Log in</font></b></td> 
</tr> 
<tr> 
<td class="row1" valign="top"> 
<table border="0" cellpadding="3" cellspacing="0" width="255" style="border-collapse: collapse" bordercolor="#111111"> 
<tr> 
<td width="68" align="left" class="explaintitle"> 
<font face="Century Gothic" size="2">Username:</font></td> 
<td width="175" align="left"> 
<font face="Century Gothic"> 
<input type="text" name="username" size="19" maxlength="40" value="" class="post" /><font size="2"> 
</font></font> 
</td> 
</tr> 
<tr> 
<td align="left" class="explaintitle" width="68"> 
<font face="Century Gothic" size="2">Password:</font></td> 
<td align="left" width="175"> 
<font face="Century Gothic"> 
<input type="password" name="password" size="19" maxlength="25" class="post" /><font size="2"> 
</font></font> 
</td> 
</tr> 
<tr> 
<td colspan="2" align="center" width="249"> 
<table border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td class="genmed"><font face="Century Gothic" size="2">Log me on automatically each visit:&</font></td> 
<td><font face="Century Gothic"> 
<input name="autologin" type="checkbox" value="ON" /></font></td> 
</tr> 
</table> 
</td> 
</tr> 
<tr> 
<td colspan="2" align="center" width="249"><font face="Century Gothic"><input type="hidden" name="redirect" value="" /> 
</font><font face="Century Gothic"><input type="submit" name="login" class="mainoption" value="Log in" /><font size="2"> 
</font></font> 
</td> 
</tr> 
</table> 
</td> 
</tr> 
</table> 
</form> 
   <a href="<?php echo $phpbb_root_path2 ?>profile.php?mode=register">Register</a> 

<?php 
} 

//That's It! Go Back and look over what you don't need. 
//Written By AJ Quick, aj@ajquick.com 
//Now Go Have Some Fun! 
?> 

</body> 
</html>

Posted: Mon Aug 18, 2003 10:09 am
by twigletmac

Posted: Mon Aug 18, 2003 11:15 am
by eclips
I read that but I dont know where the header stuff is. i cant find it. Sorry im really new to php. Any help would be good.

Posted: Mon Aug 18, 2003 5:23 pm
by Bongulim
I think you really should find where are these headers sent (the error is produced on index.php) it's probably not the file you quoted as i couldn't find it in there but just make sure there is nothing before the headers sent.
just to make sure, in the browser do viewsource to see if there is anything that goes before the error message, there shouldn't be.

Posted: Mon Aug 18, 2003 5:52 pm
by evilmonkey
The fastest, most careless way to fix this error is to use output beffering. Here's how:

Code: Select all

<?php
ob_start();
//all your code
ob_end_flush();
ob_start() MUST be the second line of your code (after <?php tag). As for ob_end_flush(), I prefer to have it last, but that's not necesary. You can put it after your header() tag.

Good luck.

Posted: Tue Aug 19, 2003 2:04 am
by eclips
I find nothing before the errors when viewing the source. I dont know what file the headers are in. I can post the code from my index page if that helps.

Posted: Tue Aug 19, 2003 2:17 am
by eclips
It works(or its messing with me, likes to do that). Thanks you so much.

Now I have one more thing...using the login script found in my first post what would I change for it to redirect back to the index page or the page that they logged in from?

Thank You, Thank You, Thank You! :D :D :D