-2

Here are the errors i am getting:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/72/10756672/html/nightmarerising/login_register.php:15) in /home/content/72/10756672/html/nightmarerising/includes/login.inc.php on line 63

Warning: Cannot modify header information - headers already sent by (output started at /home/content/72/10756672/html/nightmarerising/login_register.php:15) in /home/content/72/10756672/html/nightmarerising/includes/login.inc.php on line 63

Warning: Cannot modify header information - headers already sent by (output started at /home/content/72/10756672/html/nightmarerising/login_register.php:15) in /home/content/72/10756672/html/nightmarerising/includes/login.inc.php on line 65

Here is my code:

<?php require_once('Connections/nightmarerising.php'); ?>
<?php // Connects to your Database 
mysql_select_db("nightmarerising") 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'];     
        $acct_password = $_COOKIE['Key_my_site'];
        $check = mysql_query("SELECT username,acct_password FROM account WHERE username = '".$_POST['username']."' AND acct_password='".md5($_POST['acct_password'])."'")or die(mysql_error());

        while($info = mysql_fetch_array( $check ))          
        {       
            if ($acct_password['acct_password'] != $info['acct_password']) 
                {                       }       
            else            
                {           
                     header("Location: index.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['acct_password']) 
          {
              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 username FROM account WHERE username = '".$_POST['username']."'")or die(mysql_error());

    //Gives error if user dosen't exist
    $check2 = mysql_num_rows($check);
    if ($check2 == 0) 
    {   ?><br/><?php    
        die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>');
    }
    while($info = mysql_fetch_array( $check ))  
    {
        $_POST['acct_password'] = stripslashes($_POST['acct_password']);
        $info['acct_password'] = stripslashes($info['acct_password']);
        $_POST['acct_password'] = md5($_POST['acct_password']);

        //gives error if the password is wrong
        if ($_POST['acct_paassword'] == $info['acct_password']) 
        {     
            // 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['acct_password'], $hour);    
            //then redirect them to the members area
            header("Location: index.php");
        }
        else 
        {
            ?><br/><?php
            die('Incorrect password, please try again.');
        }
    }
 } 
else {   
// if they are not logged in 
?> 
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> 
<table border="0"> 
    <tr><td colspan=2><h1>Login</h1></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="acct_password" maxlength="50"> </td></tr>
    <tr><td colspan="2" align="right"><input type="submit" name="submit" value="Login"> </td></tr> 
</table>
</form> 
<?php } ?>

Thanks in advance for any help with this.

  • You're getting that cause you have sent something to the browser before calling header('location...'). Find that output and move the processing logic above that – Kai Qing Sep 26 '13 at 01:55
  • **Please use the search feature before asking questions!** (This applies to the rest of the Internet as well.) – Jonathon Reinhart Sep 26 '13 at 01:58

1 Answers1

-1

This is caused by sending output (echo("x")) before using a redirect (header("Location: x")).

The duplicate John linked to goes into a lot more detail, but essentially, putting ob_start(); at the start of your script will fix your problem.

Community
  • 1
  • 1
Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
  • 1
    Right but don't get in the habit of just throwing ob_ around. The first order would be to actually know what header() is doing and avoid writing horrible code in the first place – Kai Qing Sep 26 '13 at 01:59
  • I apologize for the duplicate question searched for an answers for about 6 hours today and did not run across that link. However, after reading the post it doesn't solve my error. According to the post it is on my login_register.php page which only has the html head and include links for external php files. More specifically it is on the line that includes the header section of the page. – FearlessRooster Sep 26 '13 at 02:17
  • Sorry hit enter and it submitted. @DannyBeckett Itried putting ob_start(); at the head of my script and it still didn't solve the errors as well. – FearlessRooster Sep 26 '13 at 02:17
  • @FearlessRooster It has to be the **first** thing after ` – Danny Beckett Sep 26 '13 at 02:21
  • @DannyBeckett It was the case on the include file. However, I had put it on the document calling the include right before the include not a the top. I moved it and it worked. Again sorry for duplicate, and thank you for help. – FearlessRooster Sep 26 '13 at 02:27
  • @FearlessRooster No problem; I'm glad I could help you! Just to let you know, you can click the ✓ button next to my answer to accept it and add +2 to your rep. – Danny Beckett Sep 26 '13 at 02:28