hi everyone,
i am new here and i also quite new to php. i know this issue is quite common, been spending hours try to troubleshoot for this issue earlier. i have to give up and decide to seek advice from you guys, thanks for your time.
The problem actually is because of this line below.
header('Location:welcome.php');
This is the error after login:
An error occurred in script 'D:\xampp\htdocs\book\includes\login.inc.php' on line 33:
Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\book\includes\header.html:264)
For login.inc.php code:
<?php
// This is the login page for the site.
// It's included by index.php, which receives the login form data.
// This script is created in Chapter 4.
// Array for recording errors:
$login_errors = array();
// Validate the email address:
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$e = mysqli_real_escape_string ($dbc, $_POST['email']);
} else {
$login_errors['email'] = 'Please enter a valid email address!';
}
// Validate the password:
if (!empty($_POST['pass'])) {
$p = mysqli_real_escape_string ($dbc, $_POST['pass']);
} else {
$login_errors['pass'] = 'Please enter your password!';
}
if (empty($login_errors)) { // OK to proceed!
// Query the database:
$q = "SELECT email, password FROM members1 WHERE (email='$e' AND password='$p')";
$r = mysqli_query ($dbc, $q);
if (mysqli_num_rows($r) == 1) { // A match was made.
// Get the data:
header('Location:welcome.php');
$row = mysqli_fetch_array ($r, MYSQLI_NUM);
$_SESSION['email'] = $_POST['email'];
// Jump to secured page
//
// If the user is an administrator, create a new session ID to be safe:
// This code is created at the end of Chapter 4:
} else { // No match was made.
$login_errors['login'] = 'The email address and password do not match those on file.';
}
} // End of $login_errors IF.
// Omit the closing PHP tag to avoid 'headers already sent' errors!