Jump to content

PHP Warning: Cannot modify header information - headers already sent by (output


papillonstudios

Recommended Posts

I am having a problem with my login page when I set cookies I get this error.

 

Warning: Cannot modify header information - headers already sent by (output started at /login.php:10) in /loginform.php on line 66

 

Warning: Cannot modify header information - headers already sent by (output started at /login.php:10) in /loginform.php on line 67

 

Warning: Cannot modify header information - headers already sent by (output started at /login.php:10) in /loginform.php on line 68

 

Warning: Cannot modify header information - headers already sent by (output started at /login.php:10) in loginform.php on line 72

 

I do have ob_start() at the beginning and ob_flush() and the end but i still get the error

 

<?php

 

include('config.php');

 

ob_start();

@session_start();

 

if (!isset($_POST['login'])) {

 

?>

<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">

<fieldset>

<legend>Login</legend>

<table>

<tr>

<td>Email </td>

<td><input type="text" name="email" /></td>

</tr>

<tr>

<td>Password </td>

<td><input type="password" name="password" /></td>

</tr>

<tr>

<td><input type="submit" name="login" value="Login" /></td>

</tr>

<tr>

<td><a href="<?=$siteurl?>/register.php">Register</a></td>

</tr>

</table>

</fieldset>

</form>

<?php

}

else

{

//Declare some variables

$email = secure($_POST['email']);

$password = secure($_POST['password']);

 

//Check if the form is filled out

if (!$email || !$password)

{

echo 'Please fill out the form completely';

echo '<a href="'. $siteurl .'/login.php">Go Back</a>';

}

else

{

$user = mysql_query("SELECT * FROM `users` WHERE email = '$email'");

 

if (! mysql_num_rows($user))

{

echo 'That user doe not exist';

}

else

{

//Encrypt the password

$encpass = sha1($password . $salt);

 

//Find the user

          $superquery = mysql_query("SELECT * FROM `users` WHERE email = '$email' AND password = '$encpass'");

         

          if (mysql_num_rows($superquery) == 1) {

 

            //If the user is found, set the cookies

           

                setcookie("username", $email, 0);

                setcookie("password", $encpass, 0);

                setcookie("is_logged_in", true, 0);

 

 

                //send the user to the home page

header("Location: " . $siteurl . "members.php");

 

        }

        else

        {

 

        echo 'Password was incorrect. Please try again.';

 

        }

}

}

}

 

ob_flush();

?>

 

what am i doing wrong?

Link to comment
Share on other sites

<?php

include('config.php');

ob_start();
@session_start();

if (!isset($_POST['login'])) {

?>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<fieldset>
	<legend>Login</legend>
	<table>
		<tr>
			<td>Email </td>
			<td><input type="text" name="email" /></td>
		</tr>
		<tr>
			<td>Password </td>
			<td><input type="password" name="password" /></td>
		</tr>
		<tr>
			<td><input type="submit" name="login" value="Login" /></td>
		</tr>
		<tr>
			<td><a href="<?=$siteurl?>/register.php">Register</a></td>
		</tr>
	</table>
</fieldset>
</form>
<?php
}
else
{
//Declare some variables
$email = secure($_POST['email']);
$password = secure($_POST['password']);

//Check if the form is filled out
if (!$email || !$password)
{
	echo 'Please fill out the form completely';
	echo '<a href="'. $siteurl .'/login.php">Go Back</a>';	
}
else
{
	$user = mysql_query("SELECT * FROM `users` WHERE email = '$email'");

	if (!	mysql_num_rows($user))
	{
		echo 'That user doe not exist';
	}
	else
	{
		//Encrypt the password
		$encpass = sha1($password . $salt);

		//Find the user
           	$superquery = mysql_query("SELECT * FROM `users` WHERE email = '$email' AND password = '$encpass'");
           	
           	if (mysql_num_rows($superquery) == 1) {

            	//If the user is found, set the cookies
            	
                setcookie("username", $email, 0);
                setcookie("password", $encpass, 0);
                setcookie("is_logged_in", true, 0);


                //send the user to the home page
			header("Location: " . $siteurl . "members.php");

         	} 
         	else 
         	{

    	     	echo 'Password was incorrect. Please try again.';

        	}
	}
}
}

ob_flush();
?>

Link to comment
Share on other sites

ok heres the code from the login.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>Login</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php include('loginform.php'); ?>
</body>
</html>

 

 

Im just testing but around the include(); I would have my template code

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.