File: /var/www/w230/html/attendance/login.php
<?php
session_start();
require 'db.php';
$error = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = trim($_POST["username"]);
$password = $_POST["password"];
$sql = "SELECT * FROM teachers WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();
if ($user = $result->fetch_assoc()) {
if (password_verify($password, $user["password"])) {
$_SESSION["teacher_id"] = $user["id"];
$_SESSION["teacher_name"] = $user["username"];
$_SESSION["full_name"] = $user["full_name"];
$_SESSION["role"] = $user["role"];
header("Location: dashboard.php");
exit;
} else {
$error = "รหัสผ่านไม่ถูกต้อง";
}
} else {
$error = "ไม่พบชื่อผู้ใช้ในระบบ";
}
}
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<title>เข้าสู่ระบบครูเวร</title>
<link href="https://fonts.googleapis.com/css2?family=Sarabun&display=swap" rel="stylesheet">
<style>
* {
box-sizing: border-box;
font-family: 'Sarabun', sans-serif;
}
body {
background: linear-gradient(to right, #4facfe, #00f2fe);
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.login-container {
background: #ffffff;
padding: 40px;
border-radius: 15px;
width: 100%;
max-width: 400px;
box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.15);
text-align: center;
}
.login-container img {
width: 100px;
margin-bottom: 20px;
}
h2 {
margin-bottom: 20px;
color: #333333;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 12px 15px;
margin: 10px 0 20px 0;
border: 1px solid #ccc;
border-radius: 8px;
font-size: 16px;
}
input[type="submit"] {
background-color: #4facfe;
color: white;
border: none;
padding: 12px;
width: 100%;
border-radius: 8px;
font-size: 16px;
cursor: pointer;
transition: 0.3s ease;
}
input[type="submit"]:hover {
background-color: #00c6ff;
}
.error {
color: red;
margin-bottom: 15px;
}
@media (max-width: 480px) {
.login-container {
padding: 20px;
}
}
</style>
</head>
<body>
<div class="login-container">
<!-- โลโก้ผู้ใช้ (user icon) -->
<!--<img src="https://cdn-icons-png.flaticon.com/512/1077/1077012.png" alt="User Icon">-->
<img src="logo.png" alt="User Icon">
<h2>เข้าสู่ระบบครูเวร</h2>
<?php if ($error): ?>
<div class="error"><?= $error ?></div>
<?php endif; ?>
<form method="post">
<input type="text" name="username" placeholder="ชื่อผู้ใช้" required>
<input type="password" name="password" placeholder="รหัสผ่าน" required>
<input type="submit" value="เข้าสู่ระบบ">
</form>
</div>
</body>
</html>