Page 1 of 1

error message from header help!

Posted: Sun Mar 13, 2011 7:08 pm
by simmsy
This is the error message:
Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/main.php:12) in /home/public_html/main.php on line 61

I've tried reading into this but find no solutions if anyone can help I would be very grateful. I'm just trying to get the code to take the user to register page if they not a member heres the code im using

<table border="0" width="220" align="center">
<tr>
<? if(!session_is_registered("username")){ // if session variable "username" does not exist.
echo "<td width='71'>Username:</td>
<td width='139'><input type='text' name='username' size='16' style='font-family: Times New Roman, Times, serif; font-size: 11pt;' /></td>
</tr>
<tr>
<td width='71'>Password:</td>
<td width='139'><input type='password' name='password' size='16' style='font-family: Times New Roman, Times, serif; font-size: 11pt;' /></td>
</tr>
<tr>
<td colspan='2' align='center'><input name='login' type='submit' value='Log In' style='background-color: #900002; border-color: #555555; color: #FFFFFF; font-weight: bold; width: 60px;' /></td>";
}else{
echo "<td><b>Welcome $username</b><br /><a href='logout.php'><b>Logout</b></a></td>";
}
?>
</tr>
</table>
</form></div>
<div id="menutext"><span class="class1"><a href="http://www.fightwatcher.com">Home</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://www.fightwatcher.com">News</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://www.fightwatcher.com">Profile</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://www.fightwatcher.com">Friends & Fighters</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://www.fightwatcher.com">Videos</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://www.fightwatcher.com">Groups</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://www.fightwatcher.com">Forum</a></span></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<? if(!session_is_registered("username")){
header("Location: http://www.fightwatcher.com/register.html");
}else{
include("connect.php");
$result = mysql_query("SELECT * FROM signup ORDER by date AND time LIMIT 10");
echo "<table cellpadding=0 cellspacing=0 width=163>
<tr bgcolor=#990000><td colspan=2 align=center height=24><font color=#FFFFFF><b>Newest Users:</b></font></td></tr>";
while($row = mysql_fetch_array($result))
{
$username = $row['username'];
$gender1 = $row['gender'];
if ($gender1=="male")
{
$gender2="<font color=#0066FF><b>M</b></font>";
}
if ($gender1=="female")
{
$gender2="<font color=#FF33CC><b>F</b></font>";
}
echo "<tr><td align=center width=100>$username</td><td align=center width=57>$gender2</td></tr>";
}
echo "</table>";
}
?>
</body>

Thanks

Re: error message from header help!

Posted: Mon Mar 14, 2011 12:35 am
by jim.barrett
Hi,

You have no idea how much I've struggled with exactly this lol.

The problem is with this

Code: Select all

if(!session_is_registered("username")){
header("Location: http://www.fightwatcher.com/register.html");
}else{
include("connect.php");}
Apparently, (and I'm not going to pretend that I know why)...you can't use "header('....etc')" after anything else has been printed on the page. I always put these header redirects after session_start() and before any includes, and it works. Hope this helps, and wish I could give you more explanation of why it's this way.

Re: error message from header help!

Posted: Mon Mar 14, 2011 2:56 am
by simmsy
ahh rite ok thanks