By no means an expert, but, due to the virus situation here in China I had to make online classwork. Of course, I got some help from here. Like phdr said,I don’t think you want to echo any and all errors to the user
After registering, the student, or user, logs in with an email and a password.
so first check the email:
$stmt = $pdo->prepare('SELECT * FROM allstudents21BE2 WHERE email = :email');
$stmt->execute(['email' => $email]);
if($stmt->rowCount() == 0){
$_SESSION['loginerror'] = 'No account associated with the email: ' . $email;
header('location: index.php');
exit();}
If the email checks out, check the password:
//check the password now
if($stmt->rowCount() > 0){
//get the row
$user = $stmt->fetch();
$studentnr = $user['studentnr'];
$weeknr = 'Week16';
// first check the password. If incorrect, bale out
//validate the password with $user password
if(!password_verify($password, $user['password'])){
$_SESSION['loginerror'] = '密码不对的 Incorrect password!!';
header('location: index.php');
exit();
}
I had a lot of complicated stuff to check and record the time of login for attendance, but then, if the email and password are ok, just put the address you want the user to go to:
header('location: this_week_class_page.php');
exit();
echo the $_SESSION[‘loginerror’] on the login webpage, or any other $_SESSION errors you want:
<div>
If there is a problem, you will see a message here: <br>
<?php echo $_SESSION['loginerror']; ?>
</div><br>
Thank God the virus situation is over!