Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/212293-headers-already-sent-problem/
Share on other sites

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.

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 ))
{

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

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());
}
?>

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

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.