-3

My page members.php load perfectly well. THen I press the submit button and execute the code in FORM1 .... the DB gets updated, but I get This is the error message:

Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/header.php:101) in /usr/www/users/members.php on line 84

header.php CODE

<?
    //checks cookies to make sure they are logged in 
    if(isset($_COOKIE["user"]))
    {
        $username = $_COOKIE["user"]; 
        $pass = $_COOKIE["password"];

        $sqlcheck = mysql_query(".....")or die(mysql_error()); 
        while($sqlinfo = mysql_fetch_array( $sqlcheck ))
        {
            //if the cookie has the wrong password, they are taken to the login page 
            if ($pass != $sqlinfo['password'])
            {
                $var = "HTML CODE1"; 
            }
            //otherwise they are shown the admin area    
            else
            {
                $var= "HTML CODE2"; 
            }
        }
    }
    else //if the cookie does not exist, they are taken to the login screen 
    {
        $var=  "HTML CODE3"; 
    }
?> 
<link href='http://fonts.googleapis.com/css?family=Kavoon' rel='stylesheet' type='text/css'>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.7.2.js" type="text/javascript"></script>
<style type="text/css">
</style>
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="headerBar">
  <tr >

    <td>

    <?PHP echo $var; ?>   // THIS IS LINE 101

    </td>
  </tr>
</table>

AND HERE IS THE CODE for members.php

<?
    include 'datalogin.php';
    include 'header.php';
    require_once "phpuploader/include_phpuploader.php";
    session_start();

//checks cookies to make sure they are logged in 
    if(isset($_COOKIE["user"])) {
    $username = $_COOKIE["user"]; 
    $pass = $_COOKIE["password"];
    $check = mysql_query("SELECT * FROM members WHERE email = '$username'")or die(mysql_error());
    $info = false;
        while ($info2 = mysql_fetch_array( $check ))
            {
            if(! $info)
                 { $info = $info2; }

            //if the cookie is present but has the wrong password, they are taken to the login page 
            if ($pass != $info['password']) 
            {
                header("Location: login.php"); 
                exit();
            }  
            else //if the cookie is present and doesn'T have the wrong password they are shown the admin area    
            { 
                include 'header.php';
            }
        }
}

else //if the cookie is present and doesn'T have the wrong password they are shown the login page    
            {
                header("Location: login.php"); 
                exit();
            }   


//This code runs if the form 1 has been submitted

    if (isset($_POST['submit1'])) 
    { 
        //This makes sure they did not leave any fields blank
        if (!$_POST['email'] || !$_POST['password']) 
        {
            die('Email or Password must not be empty');
        }

        // don't know why this is there ?   
        if (!get_magic_quotes_gpc()) 
        {
          $_POST['email'] = addslashes($_POST['email']);
        }

        // checks if the username is in use
        $usercheck = $_POST['email'];       
        $check = mysql_query("SELECT email FROM members WHERE email = ...... " ) or die(mysql_error());
        $check2 = mysql_num_rows($check);


        // now we insert it into the database
        $insert = "UPDATE members SET email = ..... ";
        $add_member = mysql_query($insert);     
        header('Location: members.php');   // THIS IS LINE 84
        exit();
    }   
?>
<style type="text/css">
<!--
body {
    background-color: #d2d2d2;
}
-->
</style>
<title>MY SETTINGS</title>
<link href="table_style.css" rel="stylesheet" type="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" />
<body><table width="100%" border="0" cellspacing="0" cellpadding="0" id="headerBar2" align="center">
  <tr>
    <td><div id="txtheader2">MY SETTINGS</div></td>
  </tr>
</table>
  • Your output starts as soon as you exit the PHP context, ie `?>` and start writing HTML, ie ` – Phil Nov 19 '13 at 04:00

1 Answers1

0

Your headers.php file seems to be sending output to the browser (for example the CSS links, scripts, etc). Because of this, PHP has to send HTTP headers at that very point.

If you need to modify headers, you need to do so before sending any output to the browser.

jjmontes
  • 24,679
  • 4
  • 39
  • 51