Results 1 to 8 of 8

Thread: PHP Help

  1. #1

    PHP Help

    Hi Everyone, i hope you all doing great.
    i am new to this forum and i would like to introduce my self. i graduated from Computer science program couple years ago and ihave a full time job in website.

    recently i had to deal with something new, where suddenly a warning showed on the blog we have. and few other lines that are similar.

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/o/r/******/HTML/index.php:1) in /home/content/f/o/r/******/html/includes/sessions.php on line 254

    i spend few days searching to find what could caused by i couldn't find anything to help.

    most of the suggestion were to delete the space in the opening and closing of the php files but i didnt have any spaces at all to start with. and on top of that i cannot login to my account.

    any suggestion where i should be looking ?

  2. #2
    Join Date
    May 2009
    Location
    On a Speck!!!!!
    Posts
    216
    Can you paste the complete php code that has the problem.

  3. #3
    Join Date
    May 2008
    Posts
    340
    Can you post the script which has the code which includes header() ? Also most commonly when using <?php start and end tags, make sure there is no blank line/whitespace before the <?php tag in the script.
    Twitter : http://twitter.com/eth1networks
    Contact Us : support[at]eth1.in

  4. #4
    this is sessions.php
    <?php
    /***************************************************************************
    * sessions.php
    * -------------------
    * begin : Saturday, Feb 13, 2001
    * copyright : (C) 2001 The phpBB Group
    * email : [email protected]
    *
    * $Id: sessions.php,v 1.58.2.25 2006/05/18 19:23:07 grahamje Exp $
    *
    *
    ***************************************************************************/

    /***************************************************************************
    *
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 2 of the License, or
    * (at your option) any later version.
    *
    ***************************************************************************/

    //
    // Adds/updates a new session to the database for the given userid.
    // Returns the new session ID on success.
    //
    function session_begin($user_id, $user_ip, $page_id, $auto_create = 0, $enable_autologin = 0, $admin = 0)
    {
    global $db, $board_config;
    global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $SID;

    $cookiename = $board_config['cookie_name'];
    $cookiepath = $board_config['cookie_path'];
    $cookiedomain = $board_config['cookie_domain'];
    $cookiesecure = $board_config['cookie_secure'];

    if ( isset($HTTP_COOKIE_VARS[$cookiename . '_sid']) || isset($HTTP_COOKIE_VARS[$cookiename . '_data']) )
    {
    $session_id = isset($HTTP_COOKIE_VARS[$cookiename . '_sid']) ? $HTTP_COOKIE_VARS[$cookiename . '_sid'] : '';
    $sessiondata = isset($HTTP_COOKIE_VARS[$cookiename . '_data']) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookiename . '_data'])) : array();
    $sessionmethod = SESSION_METHOD_COOKIE;
    }
    else
    {
    $sessiondata = array();
    $session_id = ( isset($HTTP_GET_VARS['sid']) ) ? $HTTP_GET_VARS['sid'] : '';
    $sessionmethod = SESSION_METHOD_GET;
    }

    //
    if (!preg_match('/^[A-Za-z0-9]*$/', $session_id))
    {
    $session_id = '';
    }

    $page_id = (int) $page_id;

    $last_visit = 0;
    $current_time = time();

    //
    // Are auto-logins allowed?
    // If allow_autologin is not set or is true then they are
    // (same behaviour as old 2.0.x session code)
    //
    if (isset($board_config['allow_autologin']) && !$board_config['allow_autologin'])
    {
    $enable_autologin = $sessiondata['autologinid'] = false;
    }

    //
    // First off attempt to join with the autologin value if we have one
    // If not, just use the user_id value
    //
    $userdata = array();

    if ($user_id != ANONYMOUS)
    {
    if (isset($sessiondata['autologinid']) && (string) $sessiondata['autologinid'] != '' && $user_id)
    {
    $sql = 'SELECT u.*
    FROM ' . USERS_TABLE . ' u, ' . SESSIONS_KEYS_TABLE . ' k
    WHERE u.user_id = ' . (int) $user_id . "
    AND u.user_active = 1
    AND k.user_id = u.user_id
    AND k.key_id = '" . md5($sessiondata['autologinid']) . "'";
    if (!($result = $db->sql_query($sql)))
    {
    message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql);
    }

    $userdata = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);

    $enable_autologin = $login = 1;
    }
    else if (!$auto_create)
    {
    $sessiondata['autologinid'] = '';
    $sessiondata['userid'] = $user_id;

    $sql = 'SELECT *
    FROM ' . USERS_TABLE . '
    WHERE user_id = ' . (int) $user_id . '
    AND user_active = 1';
    if (!($result = $db->sql_query($sql)))
    {
    message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql);
    }

    $userdata = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);

    $login = 1;
    }
    }

    //
    // At this point either $userdata should be populated or
    // one of the below is true
    // * Key didn't match one in the DB
    // * User does not exist
    // * User is inactive
    //
    if (!sizeof($userdata) || !is_array($userdata) || !$userdata)
    {
    $sessiondata['autologinid'] = '';
    $sessiondata['userid'] = $user_id = ANONYMOUS;
    $enable_autologin = $login = 0;

    $sql = 'SELECT *
    FROM ' . USERS_TABLE . '
    WHERE user_id = ' . (int) $user_id;
    if (!($result = $db->sql_query($sql)))
    {
    message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql);
    }

    $userdata = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    }


    //
    // Initial ban check against user id, IP and email address
    //
    preg_match('/(..)(..)(..)(..)/', $user_ip, $user_ip_parts);

    $sql = "SELECT ban_ip, ban_userid, ban_email
    FROM " . BANLIST_TABLE . "
    WHERE ban_ip IN ('" . $user_ip_parts[1] . $user_ip_parts[2] . $user_ip_parts[3] . $user_ip_parts[4] . "', '" . $user_ip_parts[1] . $user_ip_parts[2] . $user_ip_parts[3] . "ff', '" . $user_ip_parts[1] . $user_ip_parts[2] . "ffff', '" . $user_ip_parts[1] . "ffffff')
    OR ban_userid = $user_id";
    if ( $user_id != ANONYMOUS )
    {
    $sql .= " OR ban_email LIKE '" . str_replace("\'", "''", $userdata['user_email']) . "'
    OR ban_email LIKE '" . substr(str_replace("\'", "''", $userdata['user_email']), strpos(str_replace("\'", "''", $userdata['user_email']), "@")) . "'";
    }
    if ( !($result = $db->sql_query($sql)) )
    {
    message_die(CRITICAL_ERROR, 'Could not obtain ban information', '', __LINE__, __FILE__, $sql);
    }

    if ( $ban_info = $db->sql_fetchrow($result) )
    {
    if ( $ban_info['ban_ip'] || $ban_info['ban_userid'] || $ban_info['ban_email'] )
    {
    message_die(CRITICAL_MESSAGE, 'You_been_banned');
    }
    }

    //
    // Create or update the session
    //
    $sql = "UPDATE " . SESSIONS_TABLE . "
    SET session_user_id = $user_id, session_start = $current_time, session_time = $current_time, session_page = $page_id, session_logged_in = $login, session_admin = $admin
    WHERE session_id = '" . $session_id . "'
    AND session_ip = '$user_ip'";
    if ( !$db->sql_query($sql) || !$db->sql_affectedrows() )
    {
    $session_id = md5(dss_rand());

    $sql = "INSERT INTO " . SESSIONS_TABLE . "
    (session_id, session_user_id, session_start, session_time, session_ip, session_page, session_logged_in, session_admin)
    VALUES ('$session_id', $user_id, $current_time, $current_time, '$user_ip', $page_id, $login, $admin)";
    if ( !$db->sql_query($sql) )
    {
    message_die(CRITICAL_ERROR, 'Error creating new session', '', __LINE__, __FILE__, $sql);
    }
    }

    if ( $user_id != ANONYMOUS )
    {
    $last_visit = ( $userdata['user_session_time'] > 0 ) ? $userdata['user_session_time'] : $current_time;

    if (!$admin)
    {
    $sql = "UPDATE " . USERS_TABLE . "
    SET user_session_time = $current_time, user_session_page = $page_id, user_lastvisit = $last_visit
    WHERE user_id = $user_id";
    if ( !$db->sql_query($sql) )
    {
    message_die(CRITICAL_ERROR, 'Error updating last visit time', '', __LINE__, __FILE__, $sql);
    }
    }

    $userdata['user_lastvisit'] = $last_visit;

    //
    // Regenerate the auto-login key
    //
    if ($enable_autologin)
    {
    $auto_login_key = dss_rand() . dss_rand();

    if (isset($sessiondata['autologinid']) && (string) $sessiondata['autologinid'] != '')
    {
    $sql = 'UPDATE ' . SESSIONS_KEYS_TABLE . "
    SET last_ip = '$user_ip', key_id = '" . md5($auto_login_key) . "', last_login = $current_time
    WHERE key_id = '" . md5($sessiondata['autologinid']) . "'";
    }
    else
    {
    $sql = 'INSERT INTO ' . SESSIONS_KEYS_TABLE . "(key_id, user_id, last_ip, last_login)
    VALUES ('" . md5($auto_login_key) . "', $user_id, '$user_ip', $current_time)";
    }

    if ( !$db->sql_query($sql) )
    {
    message_die(CRITICAL_ERROR, 'Error updating session key', '', __LINE__, __FILE__, $sql);
    }

    $sessiondata['autologinid'] = $auto_login_key;
    unset($auto_login_key);
    }
    else
    {
    $sessiondata['autologinid'] = '';
    }

    // $sessiondata['autologinid'] = (!$admin) ? (( $enable_autologin && $sessionmethod == SESSION_METHOD_COOKIE ) ? $auto_login_key : '') : $sessiondata['autologinid'];
    $sessiondata['userid'] = $user_id;
    }

    $userdata['session_id'] = $session_id;
    $userdata['session_ip'] = $user_ip;
    $userdata['session_user_id'] = $user_id;
    $userdata['session_logged_in'] = $login;
    $userdata['session_page'] = $page_id;
    $userdata['session_start'] = $current_time;
    $userdata['session_time'] = $current_time;
    $userdata['session_admin'] = $admin;
    $userdata['session_key'] = $sessiondata['autologinid'];
    setcookie($cookiename . '_data', serialize($sessiondata), $current_time + 31536000, $cookiepath, $cookiedomain, $cookiesecure);
    setcookie($cookiename . '_sid', $session_id, 0, $cookiepath, $cookiedomain, $cookiesecure);

    $SID = 'sid=' . $session_id;

    return $userdata;
    }

    //
    // Checks for a given user session, tidies session table and updates user
    // sessions at each page refresh
    //
    function session_pagestart($user_ip, $thispage_id)
    {
    global $db, $lang, $board_config;
    global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $SID;

    $cookiename = $board_config['cookie_name'];
    $cookiepath = $board_config['cookie_path'];
    $cookiedomain = $board_config['cookie_domain'];
    $cookiesecure = $board_config['cookie_secure'];

    $current_time = time();
    unset($userdata);

    if ( isset($HTTP_COOKIE_VARS[$cookiename . '_sid']) || isset($HTTP_COOKIE_VARS[$cookiename . '_data']) )
    {
    $sessiondata = isset( $HTTP_COOKIE_VARS[$cookiename . '_data'] ) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookiename . '_data'])) : array();
    $session_id = isset( $HTTP_COOKIE_VARS[$cookiename . '_sid'] ) ? $HTTP_COOKIE_VARS[$cookiename . '_sid'] : '';
    $sessionmethod = SESSION_METHOD_COOKIE;
    }
    else
    {
    $sessiondata = array();
    $session_id = ( isset($HTTP_GET_VARS['sid']) ) ? $HTTP_GET_VARS['sid'] : '';
    $sessionmethod = SESSION_METHOD_GET;
    }

    //
    if (!preg_match('/^[A-Za-z0-9]*$/', $session_id))
    {
    $session_id = '';
    }

    $thispage_id = (int) $thispage_id;

    //
    // Does a session exist?
    //
    if ( !empty($session_id) )
    {
    //
    // session_id exists so go ahead and attempt to grab all
    // data in preparation
    //
    $sql = "SELECT u.*, s.*
    FROM " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u
    WHERE s.session_id = '$session_id'
    AND u.user_id = s.session_user_id";
    if ( !($result = $db->sql_query($sql)) )
    {
    message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql);
    }

    $userdata = $db->sql_fetchrow($result);

    //
    // Did the session exist in the DB?
    //
    if ( isset($userdata['user_id']) )
    {
    //
    // Do not check IP assuming equivalence, if IPv4 we'll check only first 24
    // bits ... I've been told (by vHiker) this should alleviate problems with
    // load balanced et al proxies while retaining some reliance on IP security.
    //
    $ip_check_s = substr($userdata['session_ip'], 0, 6);
    $ip_check_u = substr($user_ip, 0, 6);

    if ($ip_check_s == $ip_check_u)
    {
    $SID = ($sessionmethod == SESSION_METHOD_GET || defined('IN_ADMIN')) ? 'sid=' . $session_id : '';

    //
    // Only update session DB a minute or so after last update
    //
    if ( $current_time - $userdata['session_time'] > 60 )
    {
    // A little trick to reset session_admin on session re-usage
    $update_admin = (!defined('IN_ADMIN') && $current_time - $userdata['session_time'] > ($board_config['session_length']+60)) ? ', session_admin = 0' : '';

    $sql = "UPDATE " . SESSIONS_TABLE . "
    SET session_time = $current_time, session_page = $thispage_id$update_admin
    WHERE session_id = '" . $userdata['session_id'] . "'";
    if ( !$db->sql_query($sql) )
    {
    message_die(CRITICAL_ERROR, 'Error updating sessions table', '', __LINE__, __FILE__, $sql);
    }

    if ( $userdata['user_id'] != ANONYMOUS )
    {
    $sql = "UPDATE " . USERS_TABLE . "
    SET user_session_time = $current_time, user_session_page = $thispage_id
    WHERE user_id = " . $userdata['user_id'];
    if ( !$db->sql_query($sql) )
    {
    message_die(CRITICAL_ERROR, 'Error updating sessions table', '', __LINE__, __FILE__, $sql);
    }
    }
    session_clean($userdata['session_id']);
    setcookie($cookiename . '_data', serialize($sessiondata), $current_time + 31536000, $cookiepath, $cookiedomain, $cookiesecure);
    setcookie($cookiename . '_sid', $session_id, 0, $cookiepath, $cookiedomain, $cookiesecure);
    }

    // Add the session_key to the userdata array if it is set
    if ( isset($sessiondata['autologinid']) && $sessiondata['autologinid'] != '' )
    {
    $userdata['session_key'] = $sessiondata['autologinid'];
    }

    return $userdata;
    }
    }
    }

    //
    // If we reach here then no (valid) session exists. So we'll create a new one,
    // using the cookie user_id if available to pull basic user prefs.
    //
    $user_id = ( isset($sessiondata['userid']) ) ? intval($sessiondata['userid']) : ANONYMOUS;

    if ( !($userdata = session_begin($user_id, $user_ip, $thispage_id, TRUE)) )
    {
    message_die(CRITICAL_ERROR, 'Error creating user session', '', __LINE__, __FILE__, $sql);
    }

    return $userdata;

    }

    /**
    * Terminates the specified session
    * It will delete the entry in the sessions table for this session,
    * remove the corresponding auto-login key and reset the cookies
    */
    function session_end($session_id, $user_id)
    {
    global $db, $lang, $board_config, $userdata;
    global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $SID;

    $cookiename = $board_config['cookie_name'];
    $cookiepath = $board_config['cookie_path'];
    $cookiedomain = $board_config['cookie_domain'];
    $cookiesecure = $board_config['cookie_secure'];

    $current_time = time();

    if (!preg_match('/^[A-Za-z0-9]*$/', $session_id))
    {
    return;
    }

    //
    // Delete existing session
    //
    $sql = 'DELETE FROM ' . SESSIONS_TABLE . "
    WHERE session_id = '$session_id'
    AND session_user_id = $user_id";
    if ( !$db->sql_query($sql) )
    {
    message_die(CRITICAL_ERROR, 'Error removing user session', '', __LINE__, __FILE__, $sql);
    }

    //
    // Remove this auto-login entry (if applicable)
    //
    if ( isset($userdata['session_key']) && $userdata['session_key'] != '' )
    {
    $autologin_key = md5($userdata['session_key']);
    $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . '
    WHERE user_id = ' . (int) $user_id . "
    AND key_id = '$autologin_key'";
    if ( !$db->sql_query($sql) )
    {
    message_die(CRITICAL_ERROR, 'Error removing auto-login key', '', __LINE__, __FILE__, $sql);
    }
    }

    //
    // We expect that message_die will be called after this function,
    // but just in case it isn't, reset $userdata to the details for a guest
    //
    $sql = 'SELECT *
    FROM ' . USERS_TABLE . '
    WHERE user_id = ' . ANONYMOUS;
    if ( !($result = $db->sql_query($sql)) )
    {
    message_die(CRITICAL_ERROR, 'Error obtaining user details', '', __LINE__, __FILE__, $sql);
    }
    if ( !($userdata = $db->sql_fetchrow($result)) )
    {
    message_die(CRITICAL_ERROR, 'Error obtaining user details', '', __LINE__, __FILE__, $sql);
    }
    $db->sql_freeresult($result);


    setcookie($cookiename . '_data', '', $current_time - 31536000, $cookiepath, $cookiedomain, $cookiesecure);
    setcookie($cookiename . '_sid', '', $current_time - 31536000, $cookiepath, $cookiedomain, $cookiesecure);

    return true;
    }

    /**
    * Removes expired sessions and auto-login keys from the database
    */
    function session_clean($session_id)
    {
    global $board_config, $db;

    //
    // Delete expired sessions
    //
    $sql = 'DELETE FROM ' . SESSIONS_TABLE . '
    WHERE session_time < ' . (time() - (int) $board_config['session_length']) . "
    AND session_id <> '$session_id'";
    if ( !$db->sql_query($sql) )
    {
    message_die(CRITICAL_ERROR, 'Error clearing sessions table', '', __LINE__, __FILE__, $sql);
    }

    //
    // Delete expired auto-login keys
    // If max_autologin_time is not set then keys will never be deleted
    // (same behaviour as old 2.0.x session code)
    //
    if (!empty($board_config['max_autologin_time']) && $board_config['max_autologin_time'] > 0)
    {
    $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . '
    WHERE last_login < ' . (time() - (86400 * (int) $board_config['max_autologin_time']));
    $db->sql_query($sql);
    }

    return true;
    }

    /**
    * Reset all login keys for the specified user
    * Called on password changes
    */
    function session_reset_keys($user_id, $user_ip)
    {
    global $db, $userdata, $board_config;

    $key_sql = ($user_id == $userdata['user_id'] && !empty($userdata['session_key'])) ? "AND key_id != '" . md5($userdata['session_key']) . "'" : '';

    $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . '
    WHERE user_id = ' . (int) $user_id . "
    $key_sql";

    if ( !$db->sql_query($sql) )
    {
    message_die(CRITICAL_ERROR, 'Error removing auto-login keys', '', __LINE__, __FILE__, $sql);
    }

    $where_sql = 'session_user_id = ' . (int) $user_id;
    $where_sql .= ($user_id == $userdata['user_id']) ? " AND session_id <> '" . $userdata['session_id'] . "'" : '';
    $sql = 'DELETE FROM ' . SESSIONS_TABLE . "
    WHERE $where_sql";
    if ( !$db->sql_query($sql) )
    {
    message_die(CRITICAL_ERROR, 'Error removing user session(s)', '', __LINE__, __FILE__, $sql);
    }

    if ( !empty($key_sql) )
    {
    $auto_login_key = dss_rand() . dss_rand();

    $current_time = time();

    $sql = 'UPDATE ' . SESSIONS_KEYS_TABLE . "
    SET last_ip = '$user_ip', key_id = '" . md5($auto_login_key) . "', last_login = $current_time
    WHERE key_id = '" . md5($userdata['session_key']) . "'";

    if ( !$db->sql_query($sql) )
    {
    message_die(CRITICAL_ERROR, 'Error updating session key', '', __LINE__, __FILE__, $sql);
    }

    // And now rebuild the cookie
    $sessiondata['userid'] = $user_id;
    $sessiondata['autologinid'] = $auto_login_key;
    $cookiename = $board_config['cookie_name'];
    $cookiepath = $board_config['cookie_path'];
    $cookiedomain = $board_config['cookie_domain'];
    $cookiesecure = $board_config['cookie_secure'];

    setcookie($cookiename . '_data', serialize($sessiondata), $current_time + 31536000, $cookiepath, $cookiedomain, $cookiesecure);

    $userdata['session_key'] = $auto_login_key;
    unset($sessiondata);
    unset($auto_login_key);
    }
    }

    //
    // Append $SID to a url. Borrowed from phplib and modified. This is an
    // extra routine utilised by the session code above and acts as a wrapper
    // around every single URL and form action. If you replace the session
    // code you must include this routine, even if it's empty.
    //
    function append_sid($url, $non_html_amp = false)
    {
    global $SID;

    if ( !empty($SID) && !preg_match('#sid=#', $url) )
    {
    $url .= ( ( strpos($url, '?') !== false ) ? ( ( $non_html_amp ) ? '&' : '&amp;' ) : '?' ) . $SID;
    }

    return $url;
    }
    ?>

    and this is hesr

    <?php
    /***************************************************************************
    * page_header.php
    * -------------------
    * begin : Saturday, Feb 13, 2001
    * copyright : (C) 2001 The phpBB Group
    * email : [email protected]
    *
    * $Id: page_header.php,v 1.106.2.25 2005/10/30 15:17:14 acydburn Exp $
    *
    *
    ***************************************************************************/

    /***************************************************************************
    *
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 2 of the License, or
    * (at your option) any later version.
    *
    ***************************************************************************/

    if ( !defined('IN_PHPBB') )
    {
    die("Hacking attempt");
    }

    define('HEADER_INC', TRUE);

    //
    // gzip_compression
    //
    $do_gzip_compress = FALSE;
    if ( $board_config['gzip_compress'] )
    {
    $phpver = phpversion();

    $useragent = (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) ? $HTTP_SERVER_VARS['HTTP_USER_AGENT'] : getenv('HTTP_USER_AGENT');

    if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) )
    {
    if ( extension_loaded('zlib') )
    {
    ob_start('ob_gzhandler');
    }
    }
    else if ( $phpver > '4.0' )
    {
    if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') )
    {
    if ( extension_loaded('zlib') )
    {
    $do_gzip_compress = TRUE;
    ob_start();
    ob_implicit_flush(0);

    header('Content-Encoding: gzip');
    }
    }
    }
    }

    //
    // Parse and show the overall header.
    //
    $template->set_filenames(array(
    'overall_header' => ( empty($gen_simple_header) ) ? 'overall_header.tpl' : 'simple_header.tpl')
    );

    //
    // Generate logged in/logged out status
    //
    if ( $userdata['session_logged_in'] )
    {
    $u_login_logout = 'login.'.$phpEx.'?logout=true&amp;sid=' . $userdata['session_id'];
    $l_login_logout = $lang['Logout'] . ' [ ' . $userdata['username'] . ' ]';
    }
    else
    {
    $u_login_logout = 'login.'.$phpEx;
    $l_login_logout = $lang['Login'];
    }

    $s_last_visit = ( $userdata['session_logged_in'] ) ? create_date($board_config['default_dateformat'], $userdata['user_lastvisit'], $board_config['board_timezone']) : '';

    //
    // Get basic (usernames + totals) online
    // situation
    //
    $logged_visible_online = 0;
    $logged_hidden_online = 0;
    $guests_online = 0;
    $online_userlist = '';
    $l_online_users = '';

    if (defined('SHOW_ONLINE'))
    {

    $user_forum_sql = ( !empty($forum_id) ) ? "AND s.session_page = " . intval($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 ) . "
    $user_forum_sql
    ORDER BY u.username ASC, s.session_ip ASC";
    if( !($result = $db->sql_query($sql)) )
    {
    message_die(GENERAL_ERROR, 'Could not obtain user/online information', '', __LINE__, __FILE__, $sql);
    }

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

    $prev_user_id = 0;
    $prev_user_ip = $prev_session_ip = '';

    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("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=" . $row['user_id']) . '"' . $style_color .'>' . $row['username'] . '</a>';
    $logged_visible_online++;
    }
    else
    {
    $user_online_link = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . 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;
    }
    }

    $prev_user_id = $row['user_id'];
    }
    else
    {
    // Skip multiple sessions for one user
    if ( $row['session_ip'] != $prev_session_ip )
    {
    $guests_online++;
    }
    }

    $prev_session_ip = $row['session_ip'];
    }
    $db->sql_freeresult($result);

    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'])
    {
    $board_config['record_online_users'] = $total_online_users;
    $board_config['record_online_date'] = time();

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

    $sql = "UPDATE " . CONFIG_TABLE . "
    SET config_value = '" . $board_config['record_online_date'] . "'
    WHERE config_name = 'record_online_date'";
    if ( !$db->sql_query($sql) )
    {
    message_die(GENERAL_ERROR, 'Could not update online user record (date)', '', __LINE__, __FILE__, $sql);
    }
    }

    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);
    }

    //
    // Obtain number of new private messages
    // if user is logged in
    //
    if ( ($userdata['session_logged_in']) && (empty($gen_simple_header)) )
    {
    if ( $userdata['user_new_privmsg'] )
    {
    $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_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'];
    }
    }
    else
    {
    $icon_pm = $images['pm_no_new_msg'];
    $l_privmsgs_text = $lang['Login_check_pm'];
    $l_privmsgs_text_unread = '';
    $s_privmsg_new = 0;
    }

    //
    // Generate HTML required for Mozilla Navigation bar
    //
    if (!isset($nav_links))
    {
    $nav_links = array();
    }

    $nav_links_html = '';
    $nav_link_proto = '<link rel="%s" href="%s" title="%s" />' . "\n";
    while( list($nav_item, $nav_array) = @each($nav_links) )
    {
    if ( !empty($nav_array['url']) )
    {
    $nav_links_html .= sprintf($nav_link_proto, $nav_item, append_sid($nav_array['url']), $nav_array['title']);
    }
    else
    {
    // We have a nested array, used for items like <link rel='chapter'> that can occur more than once.
    while( list(,$nested_array) = each($nav_array) )
    {
    $nav_links_html .= sprintf($nav_link_proto, $nav_item, $nested_array['url'], $nested_array['title']);
    }
    }
    }

    // Format Timezone. We are unable to use array_pop here, because of PHP3 compatibility
    $l_timezone = explode('.', $board_config['board_timezone']);
    $l_timezone = (count($l_timezone) > 1 && $l_timezone[count($l_timezone)-1] != 0) ? $lang[sprintf('%.1f', $board_config['board_timezone'])] : $lang[number_format($board_config['board_timezone'])];
    //
    // The following assigns all _common_ variables that may be used at any point
    // in a template.
    //
    $template->assign_vars(array(
    'SITENAME' => $board_config['sitename'],
    'SITE_DESCRIPTION' => $board_config['site_desc'],
    'PAGE_TITLE' => $page_title,
    'LAST_VISIT_DATE' => sprintf($lang['You_last_visit'], $s_last_visit),
    'CURRENT_TIME' => sprintf($lang['Current_time'], create_date($board_config['default_dateformat'], time(), $board_config['board_timezone'])),
    'TOTAL_USERS_ONLINE' => $l_online_users,
    'LOGGED_IN_USER_LIST' => $online_userlist,
    'RECORD_USERS' => sprintf($lang['Record_online_users'], $board_config['record_online_users'], create_date($board_config['default_dateformat'], $board_config['record_online_date'], $board_config['board_timezone'])),
    'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text,
    'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread,
    'PRIVATE_MESSAGE_NEW_FLAG' => $s_privmsg_new,

    'PRIVMSG_IMG' => $icon_pm,

    'L_USERNAME' => $lang['Username'],
    'L_PASSWORD' => $lang['Password'],
    'L_LOGIN_LOGOUT' => $l_login_logout,
    'L_LOGIN' => $lang['Login'],
    'L_LOG_ME_IN' => $lang['Log_me_in'],
    'L_AUTO_LOGIN' => $lang['Log_me_in'],
    'L_INDEX' => sprintf($lang['Forum_Index'], $board_config['sitename']),
    'L_REGISTER' => $lang['Register'],
    'L_PROFILE' => $lang['Profile'],
    'L_SEARCH' => $lang['Search'],
    'L_PRIVATEMSGS' => $lang['Private_Messages'],
    'L_WHO_IS_ONLINE' => $lang['Who_is_Online'],
    'L_MEMBERLIST' => $lang['Memberlist'],
    'L_FAQ' => $lang['FAQ'],
    'L_USERGROUPS' => $lang['Usergroups'],
    'L_SEARCH_NEW' => $lang['Search_new'],
    'L_SEARCH_UNANSWERED' => $lang['Search_unanswered'],
    'L_SEARCH_SELF' => $lang['Search_your_posts'],
    'L_WHOSONLINE_ADMIN' => sprintf($lang['Admin_online_color'], '<span style="color:#' . $theme['fontcolor3'] . '">', '</span>'),
    'L_WHOSONLINE_MOD' => sprintf($lang['Mod_online_color'], '<span style="color:#' . $theme['fontcolor2'] . '">', '</span>'),

    'U_SEARCH_UNANSWERED' => append_sid('search.'.$phpEx.'?search_id=unanswered'),
    'U_SEARCH_SELF' => append_sid('search.'.$phpEx.'?search_id=egosearch'),
    'U_SEARCH_NEW' => append_sid('search.'.$phpEx.'?search_id=newposts'),
    'U_INDEX' => append_sid('index.'.$phpEx),
    'U_REGISTER' => append_sid('profile.'.$phpEx.'?mode=register'),
    'U_PROFILE' => append_sid('profile.'.$phpEx.'?mode=editprofile'),
    'U_PRIVATEMSGS' => append_sid('privmsg.'.$phpEx.'?folder=inbox'),
    'U_PRIVATEMSGS_POPUP' => append_sid('privmsg.'.$phpEx.'?mode=newpm'),
    'U_SEARCH' => append_sid('search.'.$phpEx),
    'U_MEMBERLIST' => append_sid('memberlist.'.$phpEx),
    'U_MODCP' => append_sid('modcp.'.$phpEx),
    'U_FAQ' => append_sid('faq.'.$phpEx),
    'U_VIEWONLINE' => append_sid('viewonline.'.$phpEx),
    'U_LOGIN_LOGOUT' => append_sid($u_login_logout),
    'U_GROUP_CP' => append_sid('groupcp.'.$phpEx),

    'S_CONTENT_DIRECTION' => $lang['DIRECTION'],
    'S_CONTENT_ENCODING' => $lang['ENCODING'],
    'S_CONTENT_DIR_LEFT' => $lang['LEFT'],
    'S_CONTENT_DIR_RIGHT' => $lang['RIGHT'],
    'S_TIMEZONE' => sprintf($lang['All_times'], $l_timezone),
    'S_LOGIN_ACTION' => append_sid('login.'.$phpEx),

    'T_HEAD_STYLESHEET' => $theme['head_stylesheet'],
    'T_BODY_BACKGROUND' => $theme['body_background'],
    'T_BODY_BGCOLOR' => '#'.$theme['body_bgcolor'],
    'T_BODY_TEXT' => '#'.$theme['body_text'],
    'T_BODY_LINK' => '#'.$theme['body_link'],
    'T_BODY_VLINK' => '#'.$theme['body_vlink'],
    'T_BODY_ALINK' => '#'.$theme['body_alink'],
    'T_BODY_HLINK' => '#'.$theme['body_hlink'],
    'T_TR_COLOR1' => '#'.$theme['tr_color1'],
    'T_TR_COLOR2' => '#'.$theme['tr_color2'],
    'T_TR_COLOR3' => '#'.$theme['tr_color3'],
    'T_TR_CLASS1' => $theme['tr_class1'],
    'T_TR_CLASS2' => $theme['tr_class2'],
    'T_TR_CLASS3' => $theme['tr_class3'],
    'T_TH_COLOR1' => '#'.$theme['th_color1'],
    'T_TH_COLOR2' => '#'.$theme['th_color2'],
    'T_TH_COLOR3' => '#'.$theme['th_color3'],
    'T_TH_CLASS1' => $theme['th_class1'],
    'T_TH_CLASS2' => $theme['th_class2'],
    'T_TH_CLASS3' => $theme['th_class3'],
    'T_TD_COLOR1' => '#'.$theme['td_color1'],
    'T_TD_COLOR2' => '#'.$theme['td_color2'],
    'T_TD_COLOR3' => '#'.$theme['td_color3'],
    'T_TD_CLASS1' => $theme['td_class1'],
    'T_TD_CLASS2' => $theme['td_class2'],
    'T_TD_CLASS3' => $theme['td_class3'],
    'T_FONTFACE1' => $theme['fontface1'],
    'T_FONTFACE2' => $theme['fontface2'],
    'T_FONTFACE3' => $theme['fontface3'],
    'T_FONTSIZE1' => $theme['fontsize1'],
    'T_FONTSIZE2' => $theme['fontsize2'],
    'T_FONTSIZE3' => $theme['fontsize3'],
    'T_FONTCOLOR1' => '#'.$theme['fontcolor1'],
    'T_FONTCOLOR2' => '#'.$theme['fontcolor2'],
    'T_FONTCOLOR3' => '#'.$theme['fontcolor3'],
    'T_SPAN_CLASS1' => $theme['span_class1'],
    'T_SPAN_CLASS2' => $theme['span_class2'],
    'T_SPAN_CLASS3' => $theme['span_class3'],

    'NAV_LINKS' => $nav_links_html)
    );

    //
    // Login box?
    //
    if ( !$userdata['session_logged_in'] )
    {
    $template->assign_block_vars('switch_user_logged_out', array());
    //
    // Allow autologin?
    //
    if (!isset($board_config['allow_autologin']) || $board_config['allow_autologin'] )
    {
    $template->assign_block_vars('switch_allow_autologin', array());
    $template->assign_block_vars('switch_user_logged_out.switch_allow_autologin', array());
    }
    }
    else
    {
    $template->assign_block_vars('switch_user_logged_in', array());

    if ( !empty($userdata['user_popup_pm']) )
    {
    $template->assign_block_vars('switch_enable_pm_popup', array());
    }
    }

    // Add no-cache control for cookies if they are set
    //$c_no_cache = (isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_data'])) ? 'no-cache="set-cookie", ' : '';

    // Work around for "current" Apache 2 + PHP module which seems to not
    // cope with private cache control setting
    if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2'))
    {
    header('Cache-Control: no-cache, pre-check=0, post-check=0');
    }
    else
    {
    header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
    }
    header('Expires: 0');
    header('Pragma: no-cache');

    $template->pparse('overall_header');
    ?>

  5. #5
    Join Date
    Jul 2003
    Location
    NC
    Posts
    270
    The response/data that comes to the client after a request is made can come so in multiple chunks or all at once.

    Once header data is sent out, you cannot modify it.

    If you want to get around this, turn PHP's output buffering to On. Restart Apache. This will cause PHP to hold all data until the end of the script is reached. In this scenario, PHP will allow you to modify header data.
    Last edited by TowerOfPower; 07-20-2009 at 07:55 PM.

  6. #6
    how to turn the buffering off? i know it should be located in config file right? but it is not.

  7. #7
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Alternatively, you could just go to the source of the problem (which is the beginning of your index.php file) and (re)move whatever has been put there.
    Quote Originally Posted by richo3880 View Post
    Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/o/r/******/HTML/index.php:1) in /home/content/f/o/r/******/html/includes/sessions.php on line 254
    The initial <?php tag should be right at the start of the index.php file, with no blank lines or other content before it. For some reason in your case there's something else there - you need to fix this.

    When you say you can't log in to your account, do you mean control panel? ftp? Without that sort of access you won't be able to do anything. Contact your host if you need help regaining access.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  8. #8
    no i cannot login to my blog account. to post something or even to get to the admin panel for the forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •