Possible Duplicate:
Headers already sent by PHP
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
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?
Here is my code:
<?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 => $line)
{
list($name, $pw) = explode(':', $line);
if($name == $username && $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 => $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.";
}
}
}
?>
<form method = "POST" action = "<?php echo $_SERVER['PHP_SELF']; ?>">
<p>
Username:<br />
<input type = "text" id="name" name="name" size="20" maxlength="40" />
</p>
<p>
Password:<br />
<input type = "password" id="apw" name="apw" size="20" maxlength="40" />
</p>
<input type="submit" id="submit" name ="submit" name ="submit" value="Log in" />
<p>
<a href="register.php">Register</a></p>
</form>