eaglelegend Posted April 3, 2008 Share Posted April 3, 2008 Warning: Cannot modify header information - headers already sent by (output started at /misc/39/000/171/334/2/user/web/eaglelegend.com/header.php:2) in /misc/39/000/171/334/2/user/web/eaglelegend.com/login.php on line 11 Cant set cookie HELP!, I get that when I try and log in my site, on IE... what would it be do you think? help much appreciated thanks! Quote Link to comment Share on other sites More sharing options...
craygo Posted April 3, 2008 Share Posted April 3, 2008 code would be nice!!! Ray Quote Link to comment Share on other sites More sharing options...
timmy0320 Posted April 3, 2008 Share Posted April 3, 2008 (opens up login.php) Ahhh yess.... there it is! For real man, you gotta show some code not just an error. We can probably tell you why you're getting the error but that's about it. Headers are already being sent somewhere in your code. You probably have some HTML or something before the header() is being called. Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted April 3, 2008 Author Share Posted April 3, 2008 Sorry! <? include("header.php"); $username = $_POST['username']; $password = $_POST['password']; if($username && $password) { $check = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `username`=\"$username\" AND `password`=\"$password\"")); if($check == 1) { if(setcookie("ipets",$username,time()+(3600*24))) { Header("Location: index.php"); } else { print "Cant set cookie"; } } else { print "Sorry, username/password mismatch!"; } } else { ?> <h2>Login</h2><p> <form action="login.php" method="post"> Username<br> <input type="text" name="username" size="20"><p> Password<br> <input type="password" name="password" size="20"><p> <input type="submit" value=" Login "></form> <? } include("footer.php"); ?> Quote Link to comment Share on other sites More sharing options...
stopblackholes Posted April 3, 2008 Share Posted April 3, 2008 your header.php file probably has html entites you cant do header redirects below html code move include("header.php"); below Header("Location: index.php"); Quote Link to comment Share on other sites More sharing options...
craygo Posted April 3, 2008 Share Posted April 3, 2008 You are trying to set a cookie in line 11 of the code above but in line 2 of header.php you have something outputting to the browser. Look at line 2 of header.php and see if you are outputting something or list the code for header.php. Ray Quote Link to comment Share on other sites More sharing options...
timmy0320 Posted April 3, 2008 Share Posted April 3, 2008 Your error states that header.php is causing the error bro. Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted April 3, 2008 Author Share Posted April 3, 2008 how do I fix this? header is: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <?php include("config.php"); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <meta name="author" content="Me"> <meta name="description" content="Eagle Legend - The newest, safest and best Virtual Pet Site in the hole of Cyberspace!"> <meta name="keywords" content="eagle legend, eaglelegend, eagle, legend, pets, pet, games, game, virtual, chat, fun, prizes, play, virtual pet, kids"> <meta name="revised" content="Eagle Legend, 04/01/08"> <title>Eagle Legend</title> <link rel="stylesheet" href="style.css" type="text/css"> <script language="JavaScript" type="text/javascript"> function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=600');"); } </script> <link rel="shortcut icon" href="favicon.ico"> <style type="text/css"> div.c1 {text-align: center} </style> </head> <body> <div class="c1"> <table border="0" width="980" cellpadding="4" cellspacing="4" bgcolor="#000000"> <tr> <td colspan="2"><a href="index.php"><img src="images/headers/banner.png" border="0" alt="Eagle Legend"></a></td> </tr> <tr> <td width="180" valign="top" bgcolor="#04AA44"> <? include("nav.php"); ?> </td> <td width="800" valign="top" bgcolor="#70BEFF"> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted April 3, 2008 Share Posted April 3, 2008 Quick fix, but read the sticky <?php ob_start(); include("header.php"); $username = $_POST['username']; $password = $_POST['password']; if($username && $password) { $check = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `username`=\"$username\" AND `password`=\"$password\"")); if($check == 1) { if(setcookie("ipets",$username,time()+(3600*24))) { Header("Location: index.php"); } else { print "Cant set cookie"; } } else { print "Sorry, username/password mismatch!"; } } else { ?> <h2>Login</h2><p> <form action="login.php" method="post"> Username<br> <input type="text" name="username" size="20"><p> Password<br> <input type="password" name="password" size="20"><p> <input type="submit" value=" Login "></form> <? } include("footer.php"); ob_endflush(); ?> Quote Link to comment Share on other sites More sharing options...
stopblackholes Posted April 3, 2008 Share Posted April 3, 2008 <?php $username = $_POST['username']; $password = $_POST['password']; if($username && $password) { $check = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `username`=\"$username\" AND `password`=\"$password\"")); if($check == 1) { if(setcookie("ipets",$username,time()+(3600*24))) { Header("Location: index.php"); } else { include("header.php"); print "Cant set cookie"; } } else { include("header.php"); print "Sorry, username/password mismatch!"; } } else { include("header.php"); ?> <h2>Login</h2><p> <form action="login.php" method="post"> Username<br> <input type="text" name="username" size="20"><p> Password<br> <input type="password" name="password" size="20"><p> <input type="submit" value=" Login "></form> <? } include("footer.php"); ?> Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted April 3, 2008 Author Share Posted April 3, 2008 Thanks cooldude832, it really works ... changing the topic a little bit, does anyone know how I can make it all "session" instead of cookies, without affecting my users etc.? Quote Link to comment Share on other sites More sharing options...
timmy0320 Posted April 3, 2008 Share Posted April 3, 2008 You have to move your include() for the header.php under the code which has the header() in it. You have HTML in the header.php which is placing it above the header() which is not allowed. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted April 3, 2008 Share Posted April 3, 2008 Thanks cooldude832, it really works ... changing the topic a little bit, does anyone know how I can make it all "session" instead of cookies, without affecting my users etc.? sorta mad at myself for showing u that because it ain't exactly the proper way to do things. If a page is to redirect via a header("location: ") it should be clear of any output before the page negotiates if it needs to redirect or not. output buffering usefulness is in running through lengthy sections to buffer the output, not to sneak around header messes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.