Jump to content

Cannot modify header information - headers already sent


w3rthlesspe0n

Recommended Posts

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>

Link to comment
Share on other sites

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'); ?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.