File manager - Edit - /home/webapp69.cm.in.th/u69319090034/Shop 034/login.php
Back
<?php // หน้า Login สำหรับ ผู้ซื้อ (Buyer), ผู้ขาย (Seller), และ ผู้ดูแลระบบ (Admin) if (session_status() === PHP_SESSION_NONE) { session_start(); } require_once 'auth.php'; $redirect = isset($_GET['redirect']) ? htmlspecialchars($_GET['redirect']) : ''; // ถ้า Login อยู่แล้ว ส่งไปยังหน้าที่เหมาะสม if (isLoggedIn()) { if (isSellerLoggedIn()) { header('Location: ' . (!empty($redirect) ? urldecode($redirect) : 'seller_dashboard.php')); } else { header('Location: ' . (!empty($redirect) ? urldecode($redirect) : 'index.php')); } exit; } $error = ''; // ประมวลผลฟอร์ม Login (ตรวจสอบ role อัตโนมัติจากฐานข้อมูล) if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = trim($_POST['username'] ?? ''); $password = $_POST['password'] ?? ''; if (empty($username) || empty($password)) { $error = 'กรุณากรอกชื่อผู้ใช้และรหัสผ่าน'; } else { // ตรวจสอบกับตาราง users ในฐานข้อมูล try { $stmt = $conn->prepare("SELECT * FROM users WHERE username = :username LIMIT 1"); $stmt->execute([':username' => $username]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password'])) { // Login สำเร็จ session_regenerate_id(true); $_SESSION['user_id'] = $user['id']; $_SESSION['user_username'] = $user['username']; $_SESSION['user_fullname'] = $user['fullname']; $_SESSION['user_email'] = $user['email']; $_SESSION['user_role'] = $user['role']; if ($user['role'] === 'admin') { $_SESSION['admin_logged_in'] = true; $_SESSION['admin_name'] = $user['fullname']; } // Redirect ตาม Role หรือ redirect query $target = !empty($_POST['redirect']) ? urldecode($_POST['redirect']) : ''; if (empty($target)) { if ($user['role'] === 'seller' || $user['role'] === 'admin') { $target = 'seller_dashboard.php'; } else { $target = 'index.php'; } } header("Location: $target"); exit; } // Fallback กรณี Admin พิเศษเดิม elseif ($username === ADMIN_USERNAME && password_verify($password, ADMIN_PASSWORD_HASH)) { session_regenerate_id(true); $_SESSION['user_id'] = 3; // admin id $_SESSION['user_username'] = 'admin'; $_SESSION['user_fullname'] = 'ผู้จัดการร้าน'; $_SESSION['user_role'] = 'admin'; $_SESSION['admin_logged_in'] = true; $_SESSION['admin_name'] = 'ผู้จัดการร้าน'; $target = !empty($_POST['redirect']) ? urldecode($_POST['redirect']) : 'admin.php'; header("Location: $target"); exit; } else { $error = 'ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง กรุณาลองใหม่อีกครั้ง'; sleep(1); } } 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>เข้าสู่ระบบ - AMARA STUDIO</title> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Sarabun:wght@300;400;500;600;700&display=swap"> <style> *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; } :root { --primary: #c5a880; --primary-hover: #b0936b; --dark: #121214; --border: #e2e8f0; --font-eng: 'Outfit', sans-serif; --font-th: 'Sarabun', sans-serif; } body { font-family: var(--font-th), var(--font-eng); background: linear-gradient(135deg, #121214 0%, #1e1e28 50%, #121214 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; padding: 20px; } .login-wrapper { width: 100%; max-width: 440px; position: relative; z-index: 2; } .login-card { background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.1); backdrop-filter: blur(20px); border-radius: 24px; padding: 40px 32px; box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5); position: relative; } /* ปุ่มกากบาทปิดกลับหน้าหลัก */ .btn-close-home { position: absolute; top: 20px; right: 20px; width: 36px; height: 36px; border-radius: 50%; background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.15); color: rgba(255, 255, 255, 0.7); display: flex; align-items: center; justify-content: center; text-decoration: none; font-size: 18px; font-weight: 300; transition: all 0.2s ease; z-index: 10; } .btn-close-home:hover { background: rgba(239, 68, 68, 0.2); color: #ef4444; border-color: rgba(239, 68, 68, 0.4); transform: rotate(90deg); } .login-header { text-align: center; margin-bottom: 28px; } .login-logo { font-family: var(--font-eng); font-size: 28px; font-weight: 800; color: white; letter-spacing: 2px; text-decoration: none; display: block; margin-bottom: 8px; } .login-logo span { color: var(--primary); } .role-tabs { display: none; } .alert-error { background: rgba(229, 62, 62, 0.15); border: 1px solid rgba(229, 62, 62, 0.3); color: #fc8181; padding: 12px 16px; border-radius: 10px; font-size: 14px; margin-bottom: 20px; } .form-group { margin-bottom: 20px; } .form-label { display: block; color: rgba(255, 255, 255, 0.7); font-size: 13px; font-weight: 600; margin-bottom: 8px; } .form-input { width: 100%; padding: 13px 16px; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.15); border-radius: 12px; color: white; font-size: 15px; font-family: var(--font-th); outline: none; transition: all 0.2s; } .form-input:focus { border-color: var(--primary); background: rgba(255, 255, 255, 0.12); } .btn-login { width: 100%; padding: 14px; background: linear-gradient(135deg, var(--primary) 0%, #a88a60 100%); color: #121214; border: none; border-radius: 12px; font-family: var(--font-th); font-size: 16px; font-weight: 700; cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; margin-top: 10px; } .btn-login:hover { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(197, 168, 128, 0.3); } .footer-note { text-align: center; margin-top: 25px; color: rgba(255, 255, 255, 0.5); font-size: 14px; } .footer-note a { color: var(--primary); text-decoration: none; font-weight: 600; } </style> </head> <body> <div class="login-wrapper"> <div class="login-card"> <!-- ปุ่มกากบาทกลับหน้าหลัก --> <a href="index.php" class="btn-close-home" title="กลับสู่หน้าหลัก">✕</a> <div class="login-header"> <a href="index.php" class="login-logo">AMARA<span>STUDIO</span></a> <p style="color: rgba(255, 255, 255, 0.6); font-size: 14px;">กรุณาเข้าสู่ระบบเพื่อดำเนินการต่อ</p> </div> <?php if (!empty($error)): ?> <div class="alert-error">⚠️ <?= htmlspecialchars($error) ?></div> <?php endif; ?> <form action="login.php" method="POST"> <input type="hidden" name="redirect" value="<?= htmlspecialchars($redirect) ?>"> <div class="form-group"> <label class="form-label">ชื่อผู้ใช้งาน (Username)</label> <input type="text" name="username" class="form-input" placeholder="กรอกชื่อผู้ใช้" required value="<?= htmlspecialchars($_POST['username'] ?? '') ?>"> </div> <div class="form-group"> <label class="form-label">รหัสผ่าน (Password)</label> <input type="password" name="password" class="form-input" placeholder="กรอกรหัสผ่าน" required> </div> <button type="submit" class="btn-login">เข้าสู่ระบบ</button> </form> <div class="footer-note"> ยังไม่มีบัญชีผู้ใช้? <a href="register.php">สมัครสมาชิกที่นี่</a> </div> </div> </div> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.29 |
proxy
|
phpinfo
|
Settings