I seem to get the following error on this page...
Warning: Cannot modify header information - headers already sent by (output started at /home/trancien/public_html/index.php:12) in /home/trancien/public_html/index.php on line 110
Warning: Cannot modify header information - headers already sent by (output started at /home/trancien/public_html/index.php:12) in /home/trancien/public_html/index.php on line 111
Warning: Cannot modify header information - headers already sent by (output started at /home/trancien/public_html/index.php:12) in /home/trancien/public_html/index.php on line 112
Warning: Cannot modify header information - headers already sent by (output started at /home/trancien/public_html/index.php:12) in /home/trancien/public_html/index.php on line 113
Here's my code. What am I doing wrong?
The lines it refers to are where the login success post script is, specifically the 4 lines with "setcookie"
PHP Code:<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
?>
<html>
<title></title>
<head>
<style type="text/css">
body{
color:white;
background-color:black;
}
#backdiv
{
width: 100%;
height: 100%;
min-width: 800px;
min-height: 800px;
background-color: black;
position: relative;
}
#frontdiv
{
width: 650px;
height: 400px;
background-color: gray;
position: absolute;
left: 500px;
top: 200px;
}
#logindiv
{
width: 350px;
height: 120px;
background-color: black;
position: absolute;
top: 200px;
left: 1250px;
}
#footerdiv
{
width: 900px;
height: 100px;
background-color: black;
position: absolute;
top: 700px;
left: 375px;
}
</style>
</head>
<body>
<?php
if ($_POST['loginbtn']){
require('connect.php');
$username = mysql_real_escape_string($_POST['user']);
$username = strip_tags($_POST['user']);
$pass = mysql_real_escape_string($_POST['pass']);
$pass = strip_tags($_POST['pass']);
mysql_close();
if ($username){
if ($pass){
require('connect.php');
$password = md5(md5("salt".$pass."salt"));
$query = mysql_query("SELECT * FROM tc_members WHERE username='$username'");
$numrows = mysql_num_rows($query);
mysql_close();
if ($numrows == 1){
require('connect.php');
$query = mysql_query("SELECT * FROM tc_members WHERE username='$username'");
$row = mysql_fetch_assoc($query);
$dbid = $row['id'];
$dbuser = $row['username'];
$dbpass = $row['password'];
$dbactive = $row['emailactivated'];
$dbadminuser = $row['admin_user'];
$dbadminentity = $row['admin_entity'];
$dbadminart = $row['admin_art'];
$dbadmingalaxy = $row['admin_galaxy'];
$dbadminglobal = $row['admin_global'];
$dbsubscription = $row['subscription'];
$dbcharacter = $row['character'];
mysql_close();
if ($password == $dbpass){
if ($dbactive == 1){
// set session info
$_SESSION['username'] = $dbuser;
$_SESSION['id'] = $dbid;
$_SESSION['character'] = $dbcharacter;
$_SESSION['subscription'] = $dbsubscription;
($dbadminuser == 1)? $_SESSION['admin_user'] = $dbadminuser : null ;
($dbadminentity == 1)? $_SESSION['admin_entity'] = $dbadminentity : null ;
($dbadminart == 1)?$_SESSION['admin_art'] = $dbadminart : null ;
($dbadmingalaxy == 1)?$_SESSION['admin_galaxy'] = $dbadmingalaxy : null ;
($dbadminglobal == 1)?$_SESSION['admin_global'] = $dbadminglobal : null ;
setcookie("username", $dbuser, 0);
setcookie("id", $dbid, 0);
setcookie("subscription", $dbsubscription, 0);
setcookie("character", $dbcharacter, 0);
$login_ip = $_SERVER['REMOTE_ADDR'];
$login_date = date("M d, Y");
$login_year = date("Y");
$login_day = date("z");
require('connect.php');
mysql_query("UPDATE tc_members SET last_logindate = '$login_date', last_loginday='$login_day', last_loginyear='$login_year', last_loginip = '$login_ip' WHERE username = '$dbuser'");
$success = "<font color='white'>Welcome <b>$dbuser</b></font>";
$enter = "<center>$success<br><hr><br><form action='members.php' method='post'><input type='submit' value='Click to Enter'></form></center>";
$query_num = mysql_query("SELECT * FROM tc_ip_log WHERE username='$dbuser' AND ip_address='$login_ip'");
$numrows = mysql_num_rows($query_num);
if(!mysql_num_rows($query_num) || mysql_num_rows($query_num) < 1){
require('connect.php');
mysql_query("INSERT INTO tc_ip_log VALUES ('', '$dbuser', '$login_ip', '$login_date', '$login_year', '$login_day', '')");
$inquery = mysql_num_rows(mysql_query("SELECT * FROM tc_ip_log017 WHERE ip_address='login_ip'"));
mysql_close();
if($inquery > 1){
require('connect.php');
mysql_query("UPDATE tc_ip_log SET login_date='$login_date' WHERE username='$dbuser' ip_address='login_ip'");
mysql_query("UPDATE tc_ip_log SET multi_flag='Yes' WHERE ip_address='login_ip'");
mysql_close();
}else ;
}elseif(mysql_num_rows($query_num) > 0){
require('connect.php');
mysql_query("UPDATE tc_ip_log SET login_date='$login_date', log_year='$login_year', log_day='$login_day' WHERE username='$dbuser' AND ip_address='$login_ip'");
$query_1 = mysql_query("SELECT * FROM tc_ip_log017 WHERE ip_address='$login_ip'");
$numrows_1 = mysql_num_rows($query_1);
mysql_close();
if($numrows_1 > 1){
require('connect.php');
mysql_query("UPDATE tc_ip_log SET login_date='$login_date' WHERE username='$dbuser' ip_address='login_ip'");
mysql_query("UPDATE tc_ip_log SET multi_flag='Yes' WHERE ip_address='$login_ip'");
mysql_close();
}else ;
}else ;
}
else
$alert = "<font color='red'>You must activate your account to login.</font>";
}
else
$alert = "<font color='red'>Incorrect password.</font>";
}
else
$alert = "<font color='red'>Incorrect username.</font>";
}
else
$alert = "<font color='red'>You must enter a password to login.</font>";
}
else
$alert = "<font color='red'>You must enter a username to login.</font>";
}
else
;
?>
<?php
echo "
<div id='backdiv'>
<div id='frontdiv'><center><font color='white'>insert 650 x 400 pic here with clickable map function</font></center></div>
<div id='logindiv'>
<table border='0' cellspacing='2' cellpadding='1'>
<tr>
<form action='index.php' method='post'>
<td colspan='4' bgcolor='gray'><center>User Login</center></td>
<tr>
<td><font color='white'>Username:</font></td>
<td colspan='2'><input type='text' name='user' tabindex='1'></td>
<td width='150'><a href='index_forgotusername.php' tabindex='5'>Lost Username</a></td>
</tr>
<tr>
<td><font color='white'>Password:</font></td>
<td colspan='2'><input type='password' name='pass' tabindex='2'></td>
<td width='150'><a href='index_forgotpassword.php' tabindex='6'>Lost Password</a></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='loginbtn' value='Login' tabindex='3'></form></td>
<form action='index_register.php' method='post'>
<td><input type='submit' value='Register' tabindex='4'></form></td>
</tr>
<tr>
<td colspan='4'><font color='red'><center> $alert </center></font></td>
</tr>
<tr>
</tr>
</table><br> $enter
</div>
<div id='footerdiv'><font color='white' size='2'><center>blah</center></font></div>
</div>";
?>
</body>
</html>



Reply With Quote
it also will speed up your PHP scripts as the internal writes go to a buffer instead of being outputed to the browser every X bytes. In fact... Output buffering was the difference between a PHP script on my computer running in 0.3 seconds compaired to 0.05 seconds or something rediculous like that anyway 
Bookmarks