Warning: Cannot modify header information

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kempy535
    New Member
    • Dec 2006
    • 14

    Warning: Cannot modify header information

    Hi I get this error code when I try to run my login script.
    Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\h tdocs\Rising sun\css.php:1) in C:\Program Files\Apache Group\Apache2\h tdocs\Rising sun\loginmeth.p hp on line 24
    This is the login script stored in loginmeth.php ;
    [php]<?php require_once 'config.php';?>
    <?php include 'opendb.php';?>
    <?php $errorMessage = '';
    if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {

    $userId = $_POST['txtUserId'];
    $password = $_POST['txtPassword'];
    $_SESSION['userid'] = $userId;
    // check if the user id and password combination exist in database
    $sql = "SELECT *
    FROM contactd
    WHERE email = '$userId' AND password = PASSWORD('$pass word')";
    //WHERE user_id = '$userId' AND user_password = PASSWORD('$pass word')";

    $result = mysql_query($sq l)
    or die('Query failed. ' . mysql_error());

    if (mysql_num_rows ($result) == 1) {
    // the user id and password match,
    // set the session
    $_SESSION['db_is_logged_i n'] = true;

    // after login we move to the main page
    header('Locatio n: cart.php');
    exit;
    } else {
    $errorMessage = 'Sorry, wrong user id / password';
    }


    }
    ?>[/php]
    and all i have in the css.php is
    [php] <?php ?>
    <style type="text/css">
    body { background-color: #000000; font-family: Arial, Helvetica, sans-serif; color: #ffffff }
    a:link { color: #ffffff }
    a:visited { color: #ffffff }
    a:hover { color: #000080 }
    a:active { color: #ff6666 }
    </style>[/php]
    Im guessing that the problem is in the css.php but im not sure why. I check and removed all extra white spaces at the end and beginnning of the <?php ?> tags but it hasn't cured it.

    Also what does" header('Locatio n: cart.php'); " Im guessing it sends you to the page specified after you login ?
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Pity you don't show us how you include the css.php. But the problem is definitely in that file. Look at the first statement in there
    Code:
    <?php ?>
    that one generates a blank char to output and ... headers sent!
    You should not use css in a php file. The usual way to include css is to have a separae CSS file, without any PHP statements or <style> statements and then do a
    Code:
    <link rel="stylesheet" href="file.css" type="text/css" />
    So remove the first statement in the css file.

    Ronald :cool:

    Comment

    • kempy535
      New Member
      • Dec 2006
      • 14

      #3
      My mistake! The css.php is called in all of the pages by,
      [php]<?php require_once 'css.php';?>[/php]
      It is under the <?php require_once 'config.php';?> on every page. Should I just use you code one the config page and then it will be called by the config page?

      Comment

      • kempy535
        New Member
        • Dec 2006
        • 14

        #4
        Okay it moaned when I put the css script link in the config file so I have put it in all the files. The error that I had has gone away :) but has been replaced by another:(
        Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\h tdocs\Rising sun\login.php:1 6) in C:\Program Files\Apache Group\Apache2\h tdocs\Rising sun\loginmeth.p hp on line 24
        This is the code for the login in page;
        [php]<?php require_once 'config.php';?>
        <link rel="stylesheet " href="rscss.css " type="text/css" />
        <html>
        <body>
        <br />
        <br />
        <br />
        <br />
        <br />
        <table width="50%" border="1">
        <tr>
        <th scope="col"><h2 >Log In</h2> for existing customers</th>
        <th scope="col"><h2 >Register</h2>if you are new to the site</th>
        </tr>
        <tr>
        <td><?php include 'loginmeth.php' ;?></td>
        <td><?php require_once 'regmeth.php';? ></td>
        </tr>
        <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
        </table>
        <?php echo "Item picked = ". $_SESSION['cartadd'];?>
        </body>
        </html>[/php]
        And this is the loginmeth page;
        [php]<?php require_once 'config.php';?>
        <?php include 'opendb.php';?>
        <?php $errorMessage = '';
        if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {

        $userId = $_POST['txtUserId'];
        $password = $_POST['txtPassword'];
        $_SESSION['userid'] = $userId;
        // check if the user id and password combination exist in database
        $sql = "SELECT *
        FROM contactd
        WHERE email = '$userId' AND password = PASSWORD('$pass word')";
        //WHERE user_id = '$userId' AND user_password = PASSWORD('$pass word')";

        $result = mysql_query($sq l)
        or die('Query failed. ' . mysql_error());

        if (mysql_num_rows ($result) == 1) {
        // the user id and password match,
        // set the session
        $_SESSION['db_is_logged_i n'] = true;

        // after login we move to the main page
        header('Locatio n: test.php');
        exit;
        } else {
        $errorMessage = 'Sorry, wrong user id / password';
        }


        }
        ?>
        <?php include 'closedb.php';? >
        // html table stuff after here[/php]

        I dont understand why its complaining. Also it doesnt seem to link to the specifed page.

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          I am sure you still have some outputting in one of your scripts, e.g. config.php or still the css file? Even a simple blank is enough to kill it. Have a look for certain,

          Ronald :cool:

          Comment

          Working...