binaryWeapon
03-02-2008, 10:43 PM
I'm getting the error that "headers were already sent" in my php prog for each time I try to call or even delete a cookie.
Warning: Cannot modify header information - headers already sent by (output started at /home/nathan/public_html/testzone/newLoginTest.php:80) in /home/nathan/public_html/testzone/newLoginTest.php on line 30
Warning: Cannot modify header information - headers already sent by (output started at /home/nathan/public_html/testzone/newLoginTest.php:80) in /home/nathan/public_html/testzone/newLoginTest.php on line 31
Warning: Cannot modify header information - headers already sent by (output started at /home/nathan/public_html/testzone/newLoginTest.php:80) in /home/nathan/public_html/testzone/newLoginTest.php on line 32
Warning: Cannot modify header information - headers already sent by (output started at /home/nathan/public_html/testzone/newLoginTest.php:80) in /home/nathan/public_html/testzone/newLoginTest.php on line 33
Warning: Cannot modify header information - headers already sent by (output started at /home/nathan/public_html/testzone/newLoginTest.php:80) in /home/nathan/public_html/testzone/newLoginTest.php on line 89
function login($username, $password, $type, $hidden)
{
mysql_connect("localhost", "*********", "*********") or die("Error inputting information to the database. Please try again later, or email us at excalo@cox.net. Sorry!");
mysql_select_db("********") or die("Error connecting to the database. Please try again later, or email us at excalo@cox.net. Sorry!");
$unames=array();
$res = mysql_query("SELECT username FROM users");
while ($row = mysql_fetch_row($res)) {
array_push ($unames, $row[0]);
}
$passes=array();
$res2 = mysql_query("SELECT password FROM users");
while ($row = mysql_fetch_row($res2)) {
array_push ($passes, $row[0]);
}
$numU = count($unames);
for($i=0; $i<$numU; $i++)
{
if($unames[$i]==$username)
{
if($passes[$i]==$password)
{
if($type=="auto")
{
$inTwoMonths = 60 * 60 * 24 * 30 * 12 * 10 + time();
setcookie("loggedin", "true", $inTwoMonths);
setcookie("username", $unames[$i], $inTwoMonths);
setcookie("password", $passes[$i], $inTwoMonths);
setcookie('content',$hidden,1);
}
}
else if($password=="")
{
if($type=="auto")
{
setcookie("loggedin", "", time()-3600);
setcookie("username", "", time()-3600);
setcookie("password", "", time()-3600);
setcookie('content','Access denied!',0);
}
elseif($type=="manual")
{
echo "No password given!";
}
}
else if($passes[$i]!=$password)
{
if($type=="auto")
{
setcookie("loggedin", "", time()-3600);
setcookie("username", "", time()-3600);
setcookie("password", "", time()-3600);
setcookie('content','Access denied!',0);
}
elseif($type=="manual")
{
echo "Incorrect password!";
}
}
$uGood="true";
}
}
if(!$uGood && $username!="")
{
echo "Incorrect username!";
}
else if(!$ugood && $username=="")
{
echo "No username given!";
}
}
if ($_COOKIE['loggedin'] && $_COOKIE['username'] && $_COOKIE['password'])
{
echo "um, hi!";
login($_COOKIE['username'], $_COOKIE['password'], 'auto', 'YO!');
}
else
{
echo "um, bye.";
}
echo $_COOKIE['content'];
setcookie("content", "", time()-3600);
Any ideas?
Oh yeah, its the beggening ideas of a login system I'm designing, if that matters at all.
Warning: Cannot modify header information - headers already sent by (output started at /home/nathan/public_html/testzone/newLoginTest.php:80) in /home/nathan/public_html/testzone/newLoginTest.php on line 30
Warning: Cannot modify header information - headers already sent by (output started at /home/nathan/public_html/testzone/newLoginTest.php:80) in /home/nathan/public_html/testzone/newLoginTest.php on line 31
Warning: Cannot modify header information - headers already sent by (output started at /home/nathan/public_html/testzone/newLoginTest.php:80) in /home/nathan/public_html/testzone/newLoginTest.php on line 32
Warning: Cannot modify header information - headers already sent by (output started at /home/nathan/public_html/testzone/newLoginTest.php:80) in /home/nathan/public_html/testzone/newLoginTest.php on line 33
Warning: Cannot modify header information - headers already sent by (output started at /home/nathan/public_html/testzone/newLoginTest.php:80) in /home/nathan/public_html/testzone/newLoginTest.php on line 89
function login($username, $password, $type, $hidden)
{
mysql_connect("localhost", "*********", "*********") or die("Error inputting information to the database. Please try again later, or email us at excalo@cox.net. Sorry!");
mysql_select_db("********") or die("Error connecting to the database. Please try again later, or email us at excalo@cox.net. Sorry!");
$unames=array();
$res = mysql_query("SELECT username FROM users");
while ($row = mysql_fetch_row($res)) {
array_push ($unames, $row[0]);
}
$passes=array();
$res2 = mysql_query("SELECT password FROM users");
while ($row = mysql_fetch_row($res2)) {
array_push ($passes, $row[0]);
}
$numU = count($unames);
for($i=0; $i<$numU; $i++)
{
if($unames[$i]==$username)
{
if($passes[$i]==$password)
{
if($type=="auto")
{
$inTwoMonths = 60 * 60 * 24 * 30 * 12 * 10 + time();
setcookie("loggedin", "true", $inTwoMonths);
setcookie("username", $unames[$i], $inTwoMonths);
setcookie("password", $passes[$i], $inTwoMonths);
setcookie('content',$hidden,1);
}
}
else if($password=="")
{
if($type=="auto")
{
setcookie("loggedin", "", time()-3600);
setcookie("username", "", time()-3600);
setcookie("password", "", time()-3600);
setcookie('content','Access denied!',0);
}
elseif($type=="manual")
{
echo "No password given!";
}
}
else if($passes[$i]!=$password)
{
if($type=="auto")
{
setcookie("loggedin", "", time()-3600);
setcookie("username", "", time()-3600);
setcookie("password", "", time()-3600);
setcookie('content','Access denied!',0);
}
elseif($type=="manual")
{
echo "Incorrect password!";
}
}
$uGood="true";
}
}
if(!$uGood && $username!="")
{
echo "Incorrect username!";
}
else if(!$ugood && $username=="")
{
echo "No username given!";
}
}
if ($_COOKIE['loggedin'] && $_COOKIE['username'] && $_COOKIE['password'])
{
echo "um, hi!";
login($_COOKIE['username'], $_COOKIE['password'], 'auto', 'YO!');
}
else
{
echo "um, bye.";
}
echo $_COOKIE['content'];
setcookie("content", "", time()-3600);
Any ideas?
Oh yeah, its the beggening ideas of a login system I'm designing, if that matters at all.