I have a script on my page that makes it so users can use my forum to log in to my main site page. It gets information from session.php in my forum directory. When not logged in I get this error. [phpBB Debug] PHP Notice: in file /includes/session.php on line 916: Cannot modify header information - headers already sent by (output started at /home/content/g/a/m/gamersinsanity/html/includes/top.php:11) [phpBB Debug] PHP Notice: in file /includes/session.php on line 916: Cannot modify header information - headers already sent by (output started at /home/content/g/a/m/gamersinsanity/html/includes/top.php:11) [phpBB Debug] PHP Notice: in file /includes/session.php on line 916: Cannot modify header information - headers already sent by (output started at /home/content/g/a/m/gamersinsanity/html/includes/top.php:11) Code (markup): Line 916 in session.php looks like this. header('Set-Cookie: ' . $name_data . (($cookietime) ? '; expires=' . $expire : '') . '; path=' . $config['cookie_path'] . $domain . ((!$config['cookie_secure']) ? '' : '; secure') . '; HttpOnly', false); } PHP: my top.php file looks like this <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Gamers Insanity</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="css.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container"> <h1>Gamers Insanity. Theres no end to gaming!<span></span></h1> <?php include('nav.php') ?> <div id="main"> Code (markup): Now, it says the error is in session.php along with top.php, but it appeard in my left sidebar which is controlled by left.php, which has more php in it than just the includes in top, so ill post that too. <div id="leftstuff"> <div id="donate_left"></div> <div class="left_box_mid"><p class="left">Please donate by clicking <a href="http://www.gameservers.com/clanpay/?clanid=c70d9c930cedbc9902bb4503d164f320">here.</a></p> </div> <div class="left_box_bot"></div> <div id="community_left"></div> <div class="left_box_mid"> <?php $user_id = $user->data['user_id']; if($user->data['user_id'] != ANONYMOUS) //If the user isnt a guest { $rank_id = $user->data['user_rank']; $result = mysql_query("SELECT * FROM phpbb_ranks WHERE rank_id='$rank_id'") or die(mysql_error()); while($row = mysql_fetch_array($result)) { if(($row['rank_title']{0} == 'A') || ($row['rank_title']{0} == 'E') || ($row['rank_title']{0} == 'I') || ($row['rank_title']{0} == 'O') || ($row['rank_title']{0} == 'U')) { $an = "an"; } else { $an = "a"; } echo "<p class=\"left\">Hello ".$user->data['username']."!</p><br><p class=\"left\"> You are ".$an." ".$row['rank_title'].".</p>"; } echo '<br><br><p><a href="'.append_sid($phpbb_root_path .'ucp.php?mode=logout&sid='.$user->session_id).'" class="left">Logout</a>'; $con = mysql_connect("p50mysql141.secureserver.net","gamers_forum","Clarefire1"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("gamers_forum", $con); $result = mysql_query("SELECT * FROM phpbb_profile_fields_data WHERE user_id='$user_id' ORDER BY user_id") or die(mysql_error()); while($row = mysql_fetch_array($result)) { if($row[pf_admin_panel] == '1') { $isadmin = 'YES'; } else { $isadmin = 'NO'; } } mysql_close($con); if($isadmin == 'YES') { echo " | <a href=\"/admin\">Go to admin panel</a></p>"; } } else { ?> <form action="/phpBB3/ucp.php?mode=login" method="post" enctype="multipart/form-data" class="loginform"> <div> <label for="username">Username:<input name="username" type="text" id="user"></label> <label for="password">Password:<input name="password" type="password" id="pass"></label> <input name="login" type="submit" id="submit" value="Login" class="btn_login"> <input type="hidden" name="redirect" value="/index.php"> </div> </form> <?php } ?> </div> <div class="left_box_bot"></div> <div id="members_left"></div> <div class="left_box_mid"> <?php $con = mysql_connect("p50mysql141.secureserver.net","gamers_content","Clarefire1"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("gamers_content", $con); $result = mysql_query("SELECT * FROM members ORDER BY member_id DESC LIMIT 10") or die(mysql_error()); echo "<ul class=\"members\">"; while($row = mysql_fetch_array($result)) { echo "<li>".$row[member_tag]."".$row[member_name]."</li>"; } echo "</ul>"; mysql_close($con); ?> </div> <div class="left_box_bot"></div> </div> PHP: My site is www.gamersinsaninty.com Thanks for the help in advance
Your php code that affects headers (setting cookies etc) has to come before any html. Even if you have a space before it there can be a problem. Looks like you need to move the code that's setting the cookie to some point before the first html.
where am i setting a cookie? in my login script? how could i move that to before any of my divs, unless I use a include script, but then it would still be after html. I was talking to another person, and they said to put my right box first in my source. that means my login will be after my right divs. i dont know how i could do this. :S another thing, why does the error only appear before i log in. after i log in it goes away, even if i login, then log out. it doesnt go away until i purge the cache and cookies.
Also on logout make sure you have it destroy sessions and cookies so they no longer exist. Thus why your having to purge as you say it the cache and cookies.
This line here header('Set-Cookie: ' . $name_data . (($cookietime) ? '; expires=' . $expire : '') . '; path=' . $config['cookie_path'] . $domain . ((!$config['cookie_secure']) ? '' : '; secure') . '; HttpOnly', false); } PHP: Cannot be placed after anything has been echo to the screen, for instance if a dot or any HTML content is being placed on your page or printed out before this then that is your problem. This MUST be before any other HTML content is printed out. If its in an include file place the include statement above any HTML content or content that will be printed out before this fires.
As an alternative to placing the header() at the beggining and adjusting other code to it, you can use ob_start() (see php manual, i can't post links ) in the beginning of your code. This will turn output buffering on, and no html requests will be send until the whole script has been executed. This is also a directive in the php.ini file, you can change it globaly from there. ob_start() enables output buffering only for the script it is called in.
That session.php file is not written by me. it is written by my forums. The forums work perfectly and always have. Just when i call data from it. I will try a session_start(); at the top of left.php and if no go, ill put ob_start(); at the top of session.php. Thanks for the replies =] EDIT: Fixed it. put ob_start(); at the very top of all my pages (top.php included in all pages). How would i go about clearing my sessions, im not handling the logout , im just pointing the user to the forum logout. it looks like this. echo '<br><br><p><a href="'.append_sid($phpbb_root_path .'ucp.php?mode=logout&sid='.$user->session_id).'" class="left">Logout</a></p>'; PHP: the "ucp.php?mode=logout&sid=" page is doing all the logging out. im just pointing them to it.