warning error message. Cannot modify header information

Discussion in 'PHP' started by mcf1992, Sep 20, 2011.

  1. #1
    Warning: Cannot modify header information - headers already sent by (output started at path/development/load/dologin.php:14) in path/development/load/dologin.php on line 33

    <?php session_start();?><html xmlns="http://www.w3.org/1999/xhtml"><head><LINK href="includes/css/style.css" rel="stylesheet" type="text/css"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Login</title></head><body><div id="header">PaymentINC</div><?phpinclude("dbsettings.php");  mysql_connect("$host", "$username", "$password")or die("cannot connect");   mysql_select_db("$db_name")or die("cannot select DB");     $username = mysql_real_escape_string($_POST['username']);  $password = md5(mysql_real_escape_string($_POST['password']));  
    $sql="SELECT * FROM `user` WHERE `username`='{$username}' AND `password`='{$password}'";  $result=mysql_query($sql);     // do the check  if($result)  {      if(mysql_num_rows($result) == 1)      {          $_SESSION['username'] = $username;        $_SESSION['password'] = $password;
            header("location: account.php");              exit();      }      else      {        echo "Wrong username/password.";      }  }  else  {      echo "The query is not true.";  }  ?>
    
    PHP:
     
    mcf1992, Sep 20, 2011 IP
  2. Rising_Star

    Rising_Star Active Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #2
    u can use header() and session_start() only before giving any output through ur page.. in this case session_start is fine but u can't use header()
     
    Rising_Star, Sep 21, 2011 IP
    jevchance likes this.
  3. jevchance

    jevchance Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    2
    Trophy Points:
    0
    #3
    Move all of your code into the first PHP block. Instead of directly echoing, save your response text to a variable. Then, in the page, just echo the variable.
     
    jevchance, Sep 21, 2011 IP
  4. patrick.s

    patrick.s Greenhorn

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    <?php session_start();?><?php
    include("dbsettings.php"); 
    mysql_connect("$host", "$username", "$password")or die("cannot connect");   
    mysql_select_db("$db_name")or die("cannot select DB");     
    $username = mysql_real_escape_string($_POST['username']);  
    $password = md5(mysql_real_escape_string($_POST['password']));  
    $sql="SELECT * FROM `user` WHERE `username`='{$username}' AND `password`='{$password}'";  
    $result=mysql_query($sql);     // do the check  if($result)  
    {      
    if(mysql_num_rows($result) == 1)      
    {          
    $_SESSION['username'] = $username;        
    $_SESSION['password'] = $password;
    header("location: account.php");              
    exit();      
    }      else      {        
    echo "Wrong username/password.";      
    }  
    }  else  {      
    echo "The query is not true.";  
    }  
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <LINK href="includes/css/style.css" rel="stylesheet" type="text/css">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Login</title>
    </head>
    <body>
    <div id="header">PaymentINC</div>
    Code (markup):
    What do you get when you use that?
     
    patrick.s, Sep 21, 2011 IP
  5. webshore88

    webshore88 Well-Known Member

    Messages:
    131
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #5
    you should separate html and php codes in separate files. Then include html into the php. Suggestion: use header() before any header manipulation, so include('html') after header().
     
    Last edited: Sep 21, 2011
    webshore88, Sep 21, 2011 IP