Hello, I'm trying to create user registration for a class website using WAMP. I have the register and activation pages working, but I am getting the same error for login, logout, forgot password, etc pages.
The error is:
An error occurred in script 'C:\wamp\www\login.php' on line 42: Cannot modify header information - headers already sent by (output started at C:\wamp\www\login.php:1)
<?php
// This is the login page for the site.
require_once ('includes/config.inc.php');
$page_title = 'Login';
include ('includes/header.html');
if (isset($_POST['submitted'])) {
require_once ('..\mysqli_connect.php');
// Validate the username:
if (!empty($_POST['username'])) {
$u = mysqli_real_escape_string ($dbc, $_POST['username']);
} else {
$u = FALSE;
echo '<p class="error">You forgot to enter your username!</p>';
}
// Validate the password:
if (!empty($_POST['pass'])) {
$p = mysqli_real_escape_string ($dbc, $_POST['pass']);
} else {
$p = FALSE;
echo '<p class="error">You forgot to enter your password!</p>';
}
if ($u && $p) { // If everything's OK.
// Query the database:
$q = "SELECT user_id, fname FROM users WHERE (username='$u' AND pass=SHA1('$p'))";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
if (@mysqli_num_rows($r) == 1) { // A match was made.
// Register the values & redirect:
$_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC);
mysqli_free_result($r);
mysqli_close($dbc);
$url = BASE_URL; // Define the URL:
ob_end_clean(); // Delete the buffer.
header("Location: $url");
exit(); // Quit the script.
} else { // No match was made.
echo '<p class="error">Either the email address and password entered do not match those on file or you have not yet activated your account.</p>';
}
} else { // If everything wasn't OK.
echo '<p class="error">Please try again.</p>';
}
mysqli_close($dbc);
} // End of SUBMIT conditional.
?>
<h1>Login</h1>
<p>Your browser must allow cookies in order to log in.</p>
<form action="login.php" method="post">
<fieldset>
<p><b>Username:</b> <input type="text" name="username" size="20" maxlength="40" /></p>
<p><b>Password:</b> <input type="password" name="pass" size="20" maxlength="20" /></p>
<div align="center"><input type="submit" name="submit" value="Login" /></div>
<input type="hidden" name="submitted" value="TRUE" />
</fieldset>
</form>
<?php // Include the HTML footer.
include ('includes/footer.html');
?>
I've googled this issue and it seems that it is a whitespace issue? I've checked this in my header and config.inc.php files and there is no empty whitespace. Any ideas?