cannot modify header information with MySQL and PHP
<p>This is my code... I cannot figure out why it keeps saying</p>

<pre><code>Warning: Cannot modify header information - headers already sent by (output started at /opt/apache/htdocs/save/header.php:10) in /opt/apache/htdocs/****/attendance.php on line 41

Warning: Cannot modify header information - headers already sent by (output started at /opt/apache/htdocs/save/header.php:10) in /opt/apache/htdocs/****/attendance.php on line 42
</code></pre>

<p>I just want the login page work. I also want to change the $_SERVER[PHP_SELF()] to the actual url so that my css and such still work. </p>

<pre><code>include('header.php');
$server = "serverName";
$dUsername = "username";
$dPass = "password";
$username = "username2";
$password = "password2";
$randomword = "randomword";

if(isset($_COOKIE['MyLoginPage'])) {
    if($_COOKIE['MyLoginPage'] == md5($password.$randomword)) {
        $conn = mysql_connect($server, $dUsername, $dPass) or die("error connecting to MySQL database");
        mysql_select_db("w3_save", $conn);
        $query = "SELECT DISTINCT MemberName FROM attendance;";
        $result = mysql_query($query, $conn) or die(mysql_error());
        echo "&lt;div id='rightColumn'&gt;&lt;div id='title'&gt;&lt;h1&gt;Attendance&lt;/h1&gt;&lt;/div&gt;&lt;div id='content'&gt;";
        while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            echo "Name: $row[MemberName] &lt;br /&gt;";
        }
        echo "&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;";

        mysql_close($conn);
        exit;
    }
    else {
        echo "&lt;p&gt;Bad Cookie. Please clear them out and try again&lt;/p&gt;";
        exit;
    }
}

if(isset($_GET['p']) &amp;&amp; $_GET['p'] == 'login') {
    if($_POST['name'] != $username) {
        echo "&lt;p&gt;Sorry the username you entered is incorrect.&lt;/p&gt;";
        exit;
    }
    else if($_POST['pass'] != $password) {
        echo "&lt;p&gt;Sorry the password you entered is incorrect.&lt;/p&gt;";
        exit;
    }
    else if($_POST['name'] == $username &amp;&amp; $_POST['pass'] == $password) {
        **setcookie('MyLoginPage', md5($_POST['pass'].$randomword));  LINE 41
        header("Location: $_SERVER[PHP_SELF]");** LINE 42
    } else {
        echo "&lt;p&gt;Sorry you could not be logged in at this time please try again&lt;/p&gt;";
    }
}


&lt;div id='rightColumn'&gt;
            &lt;div id='title'&gt;
                &lt;h1&gt;Attendance&lt;/h1&gt;
            &lt;/div&gt;
            &lt;div id='content'&gt;
                &lt;form action="``&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;?p=login" method='post'&gt;
                &lt;label&gt;Username: &lt;input type='text' name='name' id='name' /&gt;&lt;/label&gt;&lt;br /&gt;
                &lt;label&gt;Password:  &lt;input type='password' name='pass' id='pass' /&gt;&lt;/label&gt;&lt;br /&gt;
                &lt;input type='submit' id='submit' value='Login' /&gt;
                &lt;/form&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>
