woodplease Posted September 1, 2010 Share Posted September 1, 2010 I'm adding a login page to my website. When I go to the login page, and try to login, I keep getting the error "Warning: Cannot modify header information - headers already sent by (output started at C:\Users\me\Desktop\xampp\htdocs\site\login.php:7) in C:\Users\me\Desktop\xampp\htdocs\site\login.php on line 38" and I don't know why. I've looked into it, and from what I can tell its something to do with white spaces, but I cant find them. <?php include "./dbconnect.php"; ?> <?php forum_connect(); ?> <?php if(isset($_COOKIE['ID_forum'])) { $username = $_COOKIE['ID_forum']; $pass = $_COOKIE['Key_forum']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: main.php"); } } } if (isset($_POST['submit'])) { if(!$_POST['username'] | !$_POST['pass']) { die(' <h2> You did not fill in all of the fields</h2> <p<a href="login.php">Return to login page</a> '); } if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) { die(' <h2> That user does not exist in our database.<br/> </h2> <p<a href="login.php">Return to login page</a> '); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); if ($_POST['pass'] != $info['password']) { die(' <h2> Incorrect password, please try again</h2> <p<a href="login.php">Return to login page</a> '); } else { $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_forum, $_POST['username'], $hour); setcookie(Key_forum, $_POST['pass'], $hour); header("Location: main.php"); } } } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td><h2>Username:</h2></td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td><h2>Password:</h2></td><td> <input type="password" name="pass" maxlength="50"> </h2> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> Any help would be great Thanks Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/ Share on other sites More sharing options...
Alex Posted September 1, 2010 Share Posted September 1, 2010 Make sure you don't have any whitespace outside of PHP tags, that includes new lines. The error says that the output is started on line 7, so check there. Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/#findComment-1106155 Share on other sites More sharing options...
KevinM1 Posted September 1, 2010 Share Posted September 1, 2010 Also, we have a stickied topic for this: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/#findComment-1106158 Share on other sites More sharing options...
woodplease Posted September 1, 2010 Author Share Posted September 1, 2010 i've made sure there are no white spaces, and i've still got the same problem. i've also read the sticky, but still no luck fixing the problem Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/#findComment-1106160 Share on other sites More sharing options...
PFMaBiSmAd Posted September 1, 2010 Share Posted September 1, 2010 So, what are lines 1 through 7 of login.php or point out which line in the code you posted is line 7? You likely have something on the line after one of the closing ?> tags. Why do you have multiple opening/closing php tags? Just put one opening tag at the start and one closing tag at the end of your php code. Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/#findComment-1106162 Share on other sites More sharing options...
woodplease Posted September 1, 2010 Author Share Posted September 1, 2010 i've removed all the extra tags. <?php include "./dbconnect.php"; forum_connect(); if(isset($_COOKIE['ID_forum'])) { $username = $_COOKIE['ID_forum']; $pass = $_COOKIE['Key_forum']; //line 7 $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/#findComment-1106163 Share on other sites More sharing options...
mikosiko Posted September 1, 2010 Share Posted September 1, 2010 i've removed all the extra tags. <?php include "./dbconnect.php"; forum_connect(); if(isset($_COOKIE['ID_forum'])) { $username = $_COOKIE['ID_forum']; $pass = $_COOKIE['Key_forum']; //line 7 $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { and ?... it is working or not?.... if not: - Check that your first line in the code that you posted is not a blank line (nothing before your first "<?php" - Check the same for the file that you are including (dbconnect.php). hope it helps Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/#findComment-1106166 Share on other sites More sharing options...
woodplease Posted September 1, 2010 Author Share Posted September 1, 2010 it still wont work. there are no blank lines anywhere in the file, nor are there any in the dbconnect file i've included the dbconnect.php in case this helps <?php function forum_connect(){ $db = mysql_connect("localhost", "test", "password") or die(mysql_error()); mysql_select_db("forum") or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/#findComment-1106170 Share on other sites More sharing options...
Pikachu2000 Posted September 1, 2010 Share Posted September 1, 2010 You didn't write these scripts in Notepad, or another generic editor by chance, did you? I'm wondering if maybe there's a byte order mark in there somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/#findComment-1106172 Share on other sites More sharing options...
PFMaBiSmAd Posted September 1, 2010 Share Posted September 1, 2010 So, what is the current error message? Where does it say the output is occurring at? Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/#findComment-1106173 Share on other sites More sharing options...
woodplease Posted September 1, 2010 Author Share Posted September 1, 2010 no, i'm using dreamweaver. the current error message is " Warning: Cannot modify header information - headers already sent by (output started at C:\Users\me\Desktop\xampp\htdocs\SciFiStorm\headerr.php:7) in C:\Users\me\Desktop\xampp\htdocs\SciFiStorm\main.php on line 34 Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/#findComment-1106174 Share on other sites More sharing options...
PFMaBiSmAd Posted September 1, 2010 Share Posted September 1, 2010 output started at C:\Users\me\Desktop\xampp\htdocs\SciFiStorm\headerr.php:7 (line 7) ^^^ You simply need to find what is being sent at or before line 7 in that file. Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/#findComment-1106176 Share on other sites More sharing options...
woodplease Posted September 1, 2010 Author Share Posted September 1, 2010 I found the problem, there was a space next to one of the tags. when i removed it, it sorted the problem Quote Link to comment https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/#findComment-1106178 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.