w3rthlesspe0n Posted April 9, 2011 Share Posted April 9, 2011 So I have a login box in my header, which worked when i hosted it locally, but now everytime i try to login i get Cannot modify header information - headers already sent (output started at /home/content/06/7711706/html/index.php:15) in /home/content/06/7711706/html/includes/header.php on line 102 and 103 Which is the setcookie bit, not sure what i'm doing wrong though. Any idea what i'm doing wrong? Thanks <?php include('variables/variables.php'); ?> <div id="header"> <?php include('includes/flash.php'); ?> <?php mysql_connect("XXXXXXXXX", "XXXXXXX", "XXXXXX") or die(mysql_error()); mysql_select_db("XXXXXXX") or die(mysql_error()); if(isset($_COOKIE['test'])) { $username = $_COOKIE['test']; $pass = $_COOKIE['pass']; $check = mysql_query("SELECT * FROM customers WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: members.php"); } } } if (isset($_POST['submit'])) { if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } $check = mysql_query("SELECT * FROM customers WHERE username = '".$_POST['username']."'")or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=reg.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(test, $_POST['username'], $hour); setcookie(pass, $_POST['pass'], $hour); header("Location: members.php"); } } } else { ?> <form action="<?php echo $_SERVER['includes/PHP_SELF']?>" method="post"> <table bgcolor="#6699FF" height="50" border="0" style="border:hidden" align="right"> <tr><td colspan=2 align="center"><h2>Login</h2></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?></div> Quote Link to comment https://forums.phpfreaks.com/topic/233215-cannot-modify-header-information-headers-already-sent/ Share on other sites More sharing options...
Pikachu2000 Posted April 9, 2011 Share Posted April 9, 2011 Did you read the sticky topic: HEADER ERRORS - READ HERE BEFORE POSTING? Quote Link to comment https://forums.phpfreaks.com/topic/233215-cannot-modify-header-information-headers-already-sent/#findComment-1199334 Share on other sites More sharing options...
w3rthlesspe0n Posted April 9, 2011 Author Share Posted April 9, 2011 Yep, none of that worked :/ Well either that or i'm not understanding it properly Quote Link to comment https://forums.phpfreaks.com/topic/233215-cannot-modify-header-information-headers-already-sent/#findComment-1199335 Share on other sites More sharing options...
Pikachu2000 Posted April 9, 2011 Share Posted April 9, 2011 Did you misunderstand the part about not being able to output anything to the browser before sending a header? <?php include('variables/variables.php'); ?> <div id="header"> // <---- THIS IS OUTPUT <?php include('includes/flash.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/233215-cannot-modify-header-information-headers-already-sent/#findComment-1199336 Share on other sites More sharing options...
perky416 Posted April 9, 2011 Share Posted April 9, 2011 Hi, I may be wrong but i dont think you can have header(); after <div id="header">. I have read up on it before, i cant remember if its whether something has been displayed in browser so you can physically see it, it or when you view the source and something has been output before the header. Quote Link to comment https://forums.phpfreaks.com/topic/233215-cannot-modify-header-information-headers-already-sent/#findComment-1199338 Share on other sites More sharing options...
perky416 Posted April 9, 2011 Share Posted April 9, 2011 Yeah what Pikachu2000 says, i knew it was one of the 2 lol. Quote Link to comment https://forums.phpfreaks.com/topic/233215-cannot-modify-header-information-headers-already-sent/#findComment-1199339 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.