File: /var/www/w230/html/election/admin/login.php
<?php
include('../config/connect.php');
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = sha1($_POST['password']); // เข้ารหัสแบบ SHA1 เหมือนในฐานข้อมูล
$sql = "SELECT * FROM admin WHERE username='$username' AND password='$password'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) == 1) {
$_SESSION['admin'] = $username;
header("Location: dashboard.php");
} else {
$error = "ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง";
}
}
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<title>เข้าสู่ระบบผู้ดูแล</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
font-family: 'Prompt', sans-serif;
background: linear-gradient(to right, #f8ffae, #43c6ac);
padding-top: 1px;
}
.login-container {
background: #ffffff;
padding: 10px;
border-radius: 18px;
box-shadow: 0 10px 200px rgba(196, 186, 186, 0.15);
width: 100%;
max-width: 400px;
}
.logo {
width: 120px;
height: 120px;
object-fit: cover;
border-radius: 50%;
margin-bottom: 10px;
box-shadow: 0px 10px 18px rgba(0, 0, 0, 0.1);
}
.login-container h2 {
margin-bottom: 20px;
color: #333;
font-size: 24px;
}
.credit {
margin-top: 20px;
font-size: 14px;
color: #666;
text-align: center;
}
</style>
</head>
<body class="bg-light">
<div class="container mt-5">
<div class="card mx-auto shadow p-4" style="max-width: 400px;">
<div class="login-container">
<center><img src="../logo/logo.jpg" alt="โลโก้โรงเรียน" class="logo"></center>
<h4 class="text-center mb-3">ผู้ดูแลระบบ</h4>
<?php if (isset($error)) echo "<div class='alert alert-danger'>$error</div>"; ?>
<form method="post">
<div class="mb-3">
<label class="form-label">ชื่อผู้ใช้</label>
<input type="text" name="username" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">รหัสผ่าน</label>
<input type="password" name="password" class="form-control" required>
</div>
<button class="btn btn-primary w-100">เข้าสู่ระบบ</button>
</form>
</div>
</div><div class="credit">
พัฒนาโดย นายสราวุธ สมพงษ์<br>
ครูโรงเรียนบ้านหัววัวหนองนารีตาตวด
</div>
</body>
</html>