Why do I keep getting the Cannot modify header information error PHP?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/8028957/headers-already-sent-by-php">Headers already sent by PHP</a>  </p>
</blockquote>



<p>Why can't I get rid of this error: Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/login.php:43) in /Applications/XAMPP/xamppfiles/htdocs/login.php on line 24</p>

<p>Line 24 is a line with a simple bracket.  I looked for extra spaces since those are a common reason for this error (from what I've read), but I can't find any.  Any ideas?</p>

<p>Here is my code:</p>

<pre><code>&lt;?php

$check = 0;
if (isset($_POST['submit']))
{

$username = htmlentities($_POST['name']);
$username = strtolower($username);
$password = htmlentities($_POST['apw']);
$filename = getcwd() . "/passwd.txt";
$lines = file( $filename , FILE_IGNORE_NEW_LINES );
foreach($lines as $key =&gt; $line)
{
list($name, $pw) = explode(':', $line);
if($name == $username &amp;&amp; $pw == $password)
{
    $check++;
    break;  
}
}
if ($check == 1){
checkifPlayed($username);
}

else{
printf("Your username or password are invalid. Please try again.");

}

}
$played = 0;
function checkifPlayed($username) {
$results = getcwd() . "/results.txt";
$lines = file( $results , FILE_IGNORE_NEW_LINES );
foreach($lines as $key =&gt; $line)
{
    list($name, $score) = explode(':', $line);
    if($name == $username)
    {
    $played++
    break; } 
if ($played != 1){
//Redirect to page
header("location: news.php");}
else {
printf "You've already played and scored $score / 60.";
}
}
}
?&gt;

&lt;form method = "POST" action = "&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
&lt;p&gt;
Username:&lt;br /&gt;
&lt;input type = "text" id="name" name="name" size="20" maxlength="40" /&gt;
&lt;/p&gt;

&lt;p&gt;
Password:&lt;br /&gt;
&lt;input type = "password" id="apw" name="apw" size="20" maxlength="40" /&gt;
&lt;/p&gt;

&lt;input type="submit" id="submit" name ="submit" name ="submit" value="Log in" /&gt;

&lt;p&gt;
&lt;a href="register.php"&gt;Register&lt;/a&gt;&lt;/p&gt;
&lt;/form&gt;
</code></pre>
