-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvhod.php
More file actions
73 lines (60 loc) · 2.22 KB
/
Copy pathvhod.php
File metadata and controls
73 lines (60 loc) · 2.22 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
session_start();
include 'db.php';
$redirect = $_GET['redirect'] ?? 'admin.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$redirect = $_POST['redirect'] ?? 'admin.php';
$email = trim($_POST["email"]);
$password = $_POST["password"];
$query = "SELECT * FROM users WHERE email = '$email'";
$result = mysqli_query($conn, $query);
if ($result && mysqli_num_rows($result) === 1) {
$user = mysqli_fetch_assoc($result);
if (password_verify($password, $user["password"])) {
$_SESSION["user_id"] = $user["id"];
header("Location: $redirect");
exit();
} else {
$_SESSION['login_error'] = "Грешна парола!";
}
} else {
$_SESSION['login_error'] = "Невалиден имейл или парола!";
}
header("Location: vhod.php?redirect=" . urlencode($redirect));
exit();
}
$msg = $_SESSION['login_error'] ?? '';
unset($_SESSION['login_error']);
?>
<!DOCTYPE html>
<html lang="bg">
<head>
<meta charset="UTF-8">
<title>Вход</title>
<link rel="icon" type="image/png" href="assets/img/favicon.jpg">
<link rel="stylesheet" href="assets/css/auth.css">
</head>
<body>
<div class="auth-container">
<h2>Вход</h2>
<?php if ($msg): ?>
<div class="auth-message"><?= htmlspecialchars($msg) ?></div>
<?php endif; ?>
<form method="POST" action="">
<input type="email" name="email" placeholder="Имейл" required>
<input type="password" name="password" id="password" placeholder="Парола" required>
<label style="display:flex; align-items:center; gap:8px; font-size:0.9rem; cursor:pointer;">
<input type="checkbox" onclick="togglePassword()" style="width:auto; margin:0;"> Покажи паролата
</label>
<input type="hidden" name="redirect" value="<?= htmlspecialchars($redirect) ?>">
<button type="submit">Влез</button>
</form>
</div>
<script>
function togglePassword() {
const input = document.getElementById("password");
input.type = input.type === "password" ? "text" : "password";
}
</script>
</body>
</html>