-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidation.php
More file actions
58 lines (49 loc) · 1.65 KB
/
Copy pathvalidation.php
File metadata and controls
58 lines (49 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
ob_start();
// session_start();
include('include/functions.php');
if (isset($_POST['user_login'])) {
$email = trim($_POST['email']);
$password = $_POST['password'];
// Validate input
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
error("login.php", "Invalid email format.");
}
// Secure SQL query using prepared statements
$stmt = $con->prepare("SELECT * FROM users_details WHERE Email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
// If user exists
if ($result && $result->num_rows > 0) {
$user = $result->fetch_assoc();
// Verify hashed password
if (password_verify($password, $user['Password'])) {
$_SESSION['loggedUserName'] = $user['FirstName'];
$_SESSION['loggedUserId'] = $user['UserId'];
$_SESSION['userRole'] = $user['Role'];
//DO NOT use ob_clean() here. Just redirect:
switch ($user['Role']) {
case 'admin':
header("Location: admin/dashboard.php");
break;
case 'client':
header("Location: client/dashboard.php");
break;
case 'receptionist':
header("Location: receptionist/dashboard.php");
break;
default:
header("Location: index.php");
}
exit;
} else {
error("login.php", "Incorrect password.");
}
} else {
error("login.php", "No user found with that email.");
}
$stmt->close();
}
ob_end_flush();
?>