-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.php
69 lines (55 loc) · 1.93 KB
/
log.php
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
59
60
61
62
63
64
65
66
67
68
69
<?php
include 'index.php';
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE email = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
if (password_verify($password, $row['password'])) {
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['email'] = $row['email'];
$_SESSION['role'] = $row['role'];
header("Location: home_page.php");
exit();
} else {
$error_message = "Invalid password.";
}
} else {
$error_message = "No user found with this email.";
}
$stmt->close();
$conn->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Page</title>
<link rel="stylesheet" href="login_page.css">
</head>
<body>
<div class="login-container">
<h2>Login here</h2>
<?php if (isset($error_message)): ?>
<div class="error-message">
<p><?php echo $error_message; ?></p>
</div>
<?php endif; ?>
<form method="POST" action="log.php">
<input type="email" name="email" placeholder="Email" required>
<input type="password" name="password" placeholder="Password" required>
<a href="#" class="forgot-password">Forgot your password?</a>
<button type="submit" class="sign-in-btn">Sign in</button>
</form>
<button type="button" class="create-account-btn" onclick="window.location.href='reg.php';">Create new account</button>
</div>
</body>
</html>