File manager - Edit - /home/webapp69.cm.in.th/u69319090030/030 shop/admin/login.php
Back
<?php require_once __DIR__ . '/../config/db.php'; require_once __DIR__ . '/../helpers/jwt_helper.php'; require_once __DIR__ . '/../helpers/auth.php'; // อัปเดตรหัสผ่านบัญชี admin / superadmin ให้เป็น admin1234 ในฐานข้อมูลโดยอัตโนมัติเพื่อความแน่นอน try { $newHash = password_hash('admin1234', PASSWORD_BCRYPT); $pdo->exec("UPDATE users SET password = '$newHash', status = 'approved' WHERE username IN ('admin', 'superadmin') OR role IN ('admin', 'super_admin')"); } catch (PDOException $e) { // ข้ามกรณีเกิดข้อผิดพลาด } // เด้งไปหน้าแผงควบคุมเฉพาะเมื่อเป็นแอดมินเท่านั้น $currentUser = get_current_user_data(); if ($currentUser && in_array($currentUser['role'], ['admin', 'super_admin'])) { header("Location: dashboard.php"); exit(); } $error = ''; $success = ''; // ตรวจสอบข้อความผิดพลาดจากพารามิเตอร์ URL if (isset($_GET['error'])) { if ($_GET['error'] === 'unauthorized') { $error = 'ปฏิเสธการเข้าถึง บัญชีของคุณไม่มีสิทธิ์ผู้ดูแลระบบ'; } elseif ($_GET['error'] === 'pending') { $error = 'บัญชีแอดมินของคุณอยู่ระหว่างรอการอนุมัติจาก Super Admin'; } elseif ($_GET['error'] === 'not_found') { $error = 'ไม่พบข้อมูลแอดมินนี้ในระบบ'; } } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $login_input = trim($_POST['login_input'] ?? ''); $password = $_POST['password'] ?? ''; if (empty($login_input) || empty($password)) { $error = 'กรุณากรอกทั้งชื่อผู้ใช้แอดมินและรหัสผ่านความปลอดภัย'; } else { try { $stmt = $pdo->prepare("SELECT * FROM users WHERE username = ? OR email = ?"); $stmt->execute([$login_input, $login_input]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password'])) { if (!in_array($user['role'], ['admin', 'super_admin'])) { $error = 'ปฏิเสธการเข้าสู่ระบบ! บัญชีของคุณไม่มีสิทธิ์ผู้ดูแลระบบ (สำหรับแอดมินเท่านั้น)'; } elseif ($user['status'] !== 'approved') { $error = 'สถานะบัญชีแอดมินของคุณยังไม่อนุญาตให้เข้าใช้งาน (STATUS: ' . strtoupper($user['status']) . ')'; } else { $payload = [ 'id' => $user['id'], 'username' => $user['username'], 'email' => $user['email'], 'role' => $user['role'], 'status' => $user['status'] ]; $token = JWTHelper::encode($payload, JWT_SECRET); $_SESSION['auth_token'] = $token; setcookie('auth_token', $token, time() + 86400, '/', '', false, true); header("Location: dashboard.php"); exit(); } } else { $error = 'ชื่อผู้ใช้งานแอดมิน หรือรหัสผ่านไม่ถูกต้อง'; } } catch (PDOException $e) { $error = 'ระบบฐานข้อมูลขัดข้อง: ' . $e->getMessage(); } } } ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CyberShop // ระบบควบคุมหลังบ้านผู้ดูแลระบบ (Admin Only)</title> <link rel="stylesheet" href="../assets/css/style.css"> </head> <body style="display: flex; min-height: 100vh; align-items: center; justify-content: center; background: radial-gradient(circle at center, #1a080d 0%, #08080c 100%);"> <div class="cyber-card" style="width: 100%; max-width: 460px; border-color: var(--neon-red); box-shadow: 0 0 30px rgba(255,0,85,0.25);"> <div style="text-align: center; margin-bottom: 1.8rem;"> <div style="font-size: 2.5rem; margin-bottom: 0.3rem;">🛡️</div> <a href="#" class="navbar-brand" style="justify-content: center; font-size: 2rem;"> CYBER<span class="brand-red">ADMIN</span> </a> <p style="font-size: 0.85rem; letter-spacing: 2px; text-transform: uppercase; margin-top: 0.4rem; color: var(--neon-red); font-weight: bold;"> -- เฉพาะผู้ดูแลระบบเท่านั้น (RESTRICTED ADMIN ACCESS) -- </p> </div> <?php if ($error): ?> <div class="cyber-alert cyber-alert-error" style="margin-bottom: 1.2rem;"> <strong>[สิทธิ์ถูกปฏิเสธ]</strong> <?php echo htmlspecialchars($error); ?> </div> <?php endif; ?> <form action="" method="POST"> <div class="cyber-input-group"> <label class="cyber-label" for="login_input">ชื่อผู้ใช้แอดมิน / อีเมลระบบ</label> <input class="cyber-input" type="text" id="login_input" name="login_input" placeholder="กรอกชื่อบัญชีแอดมิน / อีเมล" required value="<?php echo htmlspecialchars($login_input ?? ''); ?>" style="font-size: 1rem; color: #ffffff; background: #141414;"> </div> <div class="cyber-input-group"> <label class="cyber-label" for="password">รหัสผ่านลับแอดมิน (Password)</label> <input class="cyber-input" type="password" id="password" name="password" placeholder="••••••••" required style="font-size: 1rem; color: #ffffff; background: #141414;"> </div> <button type="submit" class="btn-cyber" style="width: 100%; margin-top: 1rem; padding: 0.8rem; font-size: 1rem; border-color: var(--neon-red); background: rgba(255,0,85,0.2);"> 🔐 ยืนยันสิทธิ์และเข้าสู่ระบบแอดมิน </button> </form> <div style="text-align: center; margin-top: 1.5rem; font-size: 0.85rem; border-top: 1px solid var(--border-color); padding-top: 1rem; color: var(--text-gray);"> <!-- ปุ่มทางด่วนสำหรับลูกค้า --> <div style="margin-top: 0.5rem; background: rgba(0, 255, 102, 0.08); border: 1px dashed rgba(0, 255, 102, 0.4); border-radius: 8px; padding: 0.8rem; text-align: center;"> <div style="color: #55ff99; font-weight: bold; margin-bottom: 0.5rem; font-size: 0.9rem;"> 🛒 สำหรับลูกค้าที่ต้องการสั่งซื้อสินค้า: </div> <div style="display: flex; gap: 0.5rem; justify-content: center;"> <a href="../register.php" class="btn-cyber btn-green" style="padding: 0.4rem 0.8rem; font-size: 0.8rem; text-decoration: none;"> ✨ สมัครสมาชิกลูกค้า </a> <a href="../login.php" class="btn-cyber" style="padding: 0.4rem 0.8rem; font-size: 0.8rem; text-decoration: none; border-color: var(--neon-green); color: var(--neon-green);"> 🔑 เข้าสู่ระบบลูกค้า </a> </div> </div> </div> </div> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.24 |
proxy
|
phpinfo
|
Settings