Jump to content

[SOLVED] Warning: Cannot modify header information......


Recommended Posts

I'm really new to PHP :-\

I was wondering what to do with this error

Warning: Cannot modify header information - headers already sent by (output started at /home/nathan/public_html/header.php:10) in /home/nathan/public_html/sidebar.php on line 64

 

Warning: Cannot modify header information - headers already sent by (output started at /home/nathan/public_html/header.php:10) in /home/nathan/public_html/sidebar.php on line 65

 

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

I was searching it on google but everyone said that you just have to delete the space on the lines however

 

The Lines are:

64: setcookie(ID_my_site, $_POST['username'], $hour);

65: setcookie(Key_my_site, $_POST['pass'], $hour);

68: header("Location: members.php");

 

Link to comment
Share on other sites

This is the code I have

 

<?php

// Connects to your Database

mysql_connect("localhost", "My Username", "My Password") or die(mysql_error());

mysql_select_db("My Database") or die(mysql_error());

 

//Checks if there is a login cookie

if(isset($_COOKIE['ID_my_site']))

 

//if there is, it logs you in and directes you to the members page

{

$username = $_COOKIE['ID_my_site'];

$pass = $_COOKIE['Key_my_site'];

$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: members.php");

 

}

}

}

 

//if the login form is submitted

if (isset($_POST['submit'])) { // if form has been submitted

 

// makes sure they filled it in

if(!$_POST['username'] | !$_POST['pass']) {

die('You did not fill in a required field.');

}

// checks it against the database

 

if (!get_magic_quotes_gpc()) {

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

}

$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());

 

//Gives error if user dosen't exist

$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']);

$_POST['pass'] = md5($_POST['pass']);

 

//gives error if the password is wrong

if ($_POST['pass'] != $info['password']) {

die('Incorrect password, please try again.');

}

else

{

 

// if login is ok then we add a cookie

$_POST['username'] = stripslashes($_POST['username']);

$hour = time() + 3600;

setcookie(ID_my_site, $_POST['username'], $hour);

setcookie(Key_my_site, $_POST['pass'], $hour);

 

//then redirect them to the members area

header("Location: members.php");

}

}

}

else

{

 

// if they are not logged in

?>

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

 

<h2>Login</h2>

Username:<br>

<input type="text" name="username" maxlength="40"><br>

Password:<br>

<input type="password" name="pass" maxlength="50">

<input type="submit" name="submit" value="Login">

</form>

<?php

}

?>

 

Link to comment
Share on other sites

Header.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Swap Invites</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="favicon.ico" > 

</head>
<body>
<div id="header">
<h1>Swap Invites</h1>
</div>
<div id="menu">
<ul>
	<li class="first"><a href="index.php">Home</a></li>
	<li><a href="about.php">About</a></li>
                <li><a href="blog.php">Blog</a></li>
	<li><a href="cont.php">Contact</a></li>
</ul>
</div>

 

Sidebar.php

 

<div id="columnB">
<?php
// Connects to your Database
mysql_connect("localhost", "nathan_nathan", "qazwsxedcrfv") or die(mysql_error());
mysql_select_db("nathan_swapinvites") or die(mysql_error());

//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))

//if there is, it logs you in and directes you to the members page
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$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: members.php");

}
}
}

//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted

// makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass']) {
die('You did not fill in a required field.');
}
// checks it against the database

if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());

//Gives error if user dosen't exist
$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']);
$_POST['pass'] = md5($_POST['pass']);

//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
die('Incorrect password, please try again.');
}
else
{

// if login is ok then we add a cookie
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);

//then redirect them to the members area
header("Location: members.php");
}
}
}
else
{

// if they are not logged in
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">

<h2>Login</h2>
Username:<br>
<input type="text" name="username" maxlength="40"><br>
Password:<br>
<input type="password" name="pass" maxlength="50">
<input type="submit" name="submit" value="Login">
</form>
<?php
}
?>

Link to comment
Share on other sites

If your including header.php on the top of the sidebar.php script, then that is definitely the problem. Your header.php file is all output.

 

If header.php isn't included in sidebar.php, then try removing the top line from sidebar.php:

<div id="columnB">

 

I'm not sure if that would be considered output or not.

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.