File manager - Edit - /home/webapp69.cm.in.th/u69319090030/030 shop/register.php
Back
<?php require_once __DIR__ . '/config/db.php'; require_once __DIR__ . '/helpers/jwt_helper.php'; require_once __DIR__ . '/helpers/auth.php'; // Auto-migration: Ensure columns exist try { $pdo->exec("ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `full_name` VARCHAR(100) DEFAULT NULL AFTER `password`"); $pdo->exec("ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `phone` VARCHAR(20) DEFAULT NULL AFTER `full_name`"); $pdo->exec("ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `address` TEXT DEFAULT NULL AFTER `phone`"); $pdo->exec("ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `avatar` VARCHAR(255) DEFAULT NULL AFTER `status`"); } catch (PDOException $e) { // Ignore migration error if columns exist or ALTER unsupported } if (get_current_user_data()) { header("Location: index.php"); exit(); } $error = ''; $success = ''; $username = ''; $full_name = ''; $email = ''; $phone = ''; $address = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = trim($_POST['username'] ?? ''); $full_name = trim($_POST['full_name'] ?? ''); $email = trim($_POST['email'] ?? ''); $phone = trim($_POST['phone'] ?? ''); $address = trim($_POST['address'] ?? ''); $password = $_POST['password'] ?? ''; $confirm_password = $_POST['confirm_password'] ?? ''; if (empty($username) || empty($email) || empty($password) || empty($confirm_password)) { $error = 'กรุณากรอกชื่อผู้ใช้งาน อีเมล และรหัสผ่านให้ครบถ้วน'; } elseif (!preg_match('/^[a-zA-Z0-9_]{3,30}$/', $username)) { $error = 'ชื่อผู้ใช้ต้องประกอบด้วยตัวอักษรภาษาอังกฤษ ตัวเลข หรือ _ ความยาว 3-30 ตัวอักษร'; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error = 'รูปแบบอีเมลไม่ถูกต้อง กรุณาตรวจสอบอีกครั้ง'; } elseif (strlen($password) < 6) { $error = 'รหัสผ่านต้องมีความยาวอย่างน้อย 6 ตัวอักษรเพื่อความปลอดภัย'; } elseif ($password !== $confirm_password) { $error = 'รหัสผ่านและการยืนยันรหัสผ่านไม่ตรงกัน'; } else { try { $stmt = $pdo->prepare("SELECT id FROM users WHERE username = ? OR email = ?"); $stmt->execute([$username, $email]); if ($stmt->fetch()) { $error = 'ชื่อผู้ใช้งานหรืออีเมลนี้ถูกใช้งานสมัครสมาชิกไปแล้ว'; } else { $hashed_password = password_hash($password, PASSWORD_BCRYPT); $stmt = $pdo->prepare("INSERT INTO users (username, full_name, email, phone, address, password, role, status) VALUES (?, ?, ?, ?, ?, ?, 'customer', 'approved')"); $stmt->execute([$username, $full_name, $email, $phone, $address, $hashed_password]); $newUserId = $pdo->lastInsertId(); // สร้างเซสชันล็อกอินเข้าใช้งานให้ลูกค้าทันที $payload = [ 'id' => $newUserId, 'username' => $username, 'email' => $email, 'role' => 'customer', 'status' => 'approved' ]; $token = JWTHelper::encode($payload, JWT_SECRET); $_SESSION['auth_token'] = $token; setcookie('auth_token', $token, time() + 86400, '/', '', false, true); header("Location: index.php?registered=1"); exit(); } } 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 // สมัครสมาชิกลูกค้าใหม่ (Register Member)</title> <link rel="stylesheet" href="assets/css/style.css"> <style> .register-container { width: 100%; max-width: 540px; margin: 2rem auto; } .strength-meter { height: 6px; border-radius: 3px; background: #222; margin-top: 6px; overflow: hidden; transition: all 0.3s ease; } .strength-bar { height: 100%; width: 0%; transition: width 0.3s ease, background-color 0.3s ease; } .pw-toggle { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: none; color: #888; cursor: pointer; font-size: 1.1rem; } .pw-toggle:hover { color: var(--neon-green); } .input-relative { position: relative; } .match-badge { font-size: 0.8rem; margin-top: 4px; display: block; } </style> </head> <body style="display: flex; min-height: 100vh; align-items: center; justify-content: center; background: radial-gradient(circle at center, #051a10 0%, #08080c 100%); padding: 2rem 1rem;"> <div class="register-container"> <div class="cyber-card" style="border-color: var(--neon-green); box-shadow: 0 0 35px rgba(0, 255, 102, 0.22);"> <div style="text-align: center; margin-bottom: 1.8rem;"> <div style="font-size: 2.8rem; margin-bottom: 0.2rem; filter: drop-shadow(0 0 10px rgba(0, 255, 102, 0.5));">🛡️</div> <a href="index.php" class="navbar-brand" style="justify-content: center; font-size: 2.2rem; text-decoration: none;"> CYBER<span style="color: var(--neon-green); text-shadow: 0 0 12px var(--glow-green);">MEMBER</span> </a> <p style="font-size: 0.88rem; letter-spacing: 1.5px; text-transform: uppercase; margin-top: 0.4rem; color: #55ff99; font-weight: bold;"> -- สมัครสมาชิกลูกค้าเพื่อรับสิทธิพิเศษ & สั่งซื้อสินค้า -- </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="register.php" method="POST" id="regForm"> <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; margin-bottom: 1rem;"> <div class="cyber-input-group" style="margin-bottom: 0;"> <label class="cyber-label" for="username" style="color: #ffffff;">👤 ชื่อผู้ใช้ (Username) *</label> <input class="cyber-input" type="text" id="username" name="username" placeholder="ภาษาอังกฤษ/ตัวเลข" required value="<?php echo htmlspecialchars($username); ?>" style="font-size: 0.95rem; color: #ffffff; background: #141414;"> </div> <div class="cyber-input-group" style="margin-bottom: 0;"> <label class="cyber-label" for="full_name" style="color: #ffffff;">📛 ชื่อ - นามสกุลจริง</label> <input class="cyber-input" type="text" id="full_name" name="full_name" placeholder="นายสมชาย ใจดี" value="<?php echo htmlspecialchars($full_name); ?>" style="font-size: 0.95rem; color: #ffffff; background: #141414;"> </div> </div> <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; margin-bottom: 1rem;"> <div class="cyber-input-group" style="margin-bottom: 0;"> <label class="cyber-label" for="email" style="color: #ffffff;">✉️ อีเมล (Email) *</label> <input class="cyber-input" type="email" id="email" name="email" placeholder="user@example.com" required value="<?php echo htmlspecialchars($email); ?>" style="font-size: 0.95rem; color: #ffffff; background: #141414;"> </div> <div class="cyber-input-group" style="margin-bottom: 0;"> <label class="cyber-label" for="phone" style="color: #ffffff;">📞 เบอร์โทรศัพท์</label> <input class="cyber-input" type="tel" id="phone" name="phone" placeholder="0812345678" value="<?php echo htmlspecialchars($phone); ?>" style="font-size: 0.95rem; color: #ffffff; background: #141414;"> </div> </div> <div class="cyber-input-group" style="margin-bottom: 1rem;"> <label class="cyber-label" for="address" style="color: #ffffff;">🏠 ที่อยู่สำหรับจัดส่งสินค้า</label> <textarea class="cyber-input" id="address" name="address" rows="2" placeholder="บ้านเลขที่, ถนน, แขวง/ตำบล, เขต/อำเภอ, จังหวัด, รหัสไปรษณีย์" style="font-size: 0.92rem; color: #ffffff; background: #141414; resize: vertical; min-height: 60px;"><?php echo htmlspecialchars($address); ?></textarea> </div> <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; margin-bottom: 1.2rem;"> <div class="cyber-input-group" style="margin-bottom: 0;"> <label class="cyber-label" for="password" style="color: #ffffff; font-size: 0.85rem;">🔑 รหัสผ่าน *</label> <div class="input-relative"> <input class="cyber-input" type="password" id="password" name="password" placeholder="อย่างน้อย 6 ตัวอักษร" required style="font-size: 0.95rem; color: #ffffff; background: #141414; padding-right: 40px;"> <button type="button" class="pw-toggle" onclick="togglePassword('password', this)">👁️</button> </div> <div class="strength-meter"><div id="strengthBar" class="strength-bar"></div></div> <span id="strengthText" style="font-size: 0.75rem; color: #888; margin-top: 2px; display: block;"></span> </div> <div class="cyber-input-group" style="margin-bottom: 0;"> <label class="cyber-label" for="confirm_password" style="color: #ffffff; font-size: 0.85rem;">🔐 ยืนยันรหัสผ่าน *</label> <div class="input-relative"> <input class="cyber-input" type="password" id="confirm_password" name="confirm_password" placeholder="กรอกรหัสผ่านอีกครั้ง" required style="font-size: 0.95rem; color: #ffffff; background: #141414; padding-right: 40px;"> <button type="button" class="pw-toggle" onclick="togglePassword('confirm_password', this)">👁️</button> </div> <span id="matchBadge" class="match-badge"></span> </div> </div> <button type="submit" class="btn-cyber btn-green" style="width: 100%; margin-top: 0.5rem; padding: 0.9rem; font-size: 1.05rem; font-weight: bold; border-radius: 4px; text-shadow: 0 0 8px rgba(0,255,102,0.5);"> ✨ ยืนยันการสมัครสมาชิกและเข้าสู่ระบบ </button> </form> <div style="text-align: center; margin-top: 1.5rem; font-size: 0.9rem; border-top: 1px solid var(--border-color); padding-top: 1.2rem; color: var(--text-gray);"> เป็นสมาชิก CyberShop อยู่แล้ว? <a href="login.php" style="color: var(--neon-green); text-decoration: none; font-weight: bold; text-shadow: 0 0 5px var(--glow-green);">เข้าสู่ระบบที่นี่ »</a> </div> </div> </div> <script> function togglePassword(inputId, btn) { const input = document.getElementById(inputId); if (input.type === 'password') { input.type = 'text'; btn.textContent = '🔒'; } else { input.type = 'password'; btn.textContent = '👁️'; } } const passwordInput = document.getElementById('password'); const confirmInput = document.getElementById('confirm_password'); const strengthBar = document.getElementById('strengthBar'); const strengthText = document.getElementById('strengthText'); const matchBadge = document.getElementById('matchBadge'); passwordInput.addEventListener('input', function() { const val = this.value; let score = 0; if (val.length >= 6) score += 30; if (val.length >= 10) score += 20; if (/[A-Z]/.test(val)) score += 20; if (/[0-9]/.test(val)) score += 15; if (/[^A-Za-z0-9]/.test(val)) score += 15; strengthBar.style.width = score + '%'; if (val.length === 0) { strengthBar.style.width = '0%'; strengthText.textContent = ''; } else if (score < 40) { strengthBar.style.backgroundColor = '#ff3366'; strengthText.textContent = '🔴 รหัสผ่านค่อนข้างง่าย (ควรผสมตัวเลข/อักษรใหญ่)'; strengthText.style.color = '#ff3366'; } else if (score < 75) { strengthBar.style.backgroundColor = '#ffcc00'; strengthText.textContent = '🟡 รหัสผ่านปานกลาง'; strengthText.style.color = '#ffcc00'; } else { strengthBar.style.backgroundColor = '#00ff66'; strengthText.textContent = '🟢 รหัสผ่านปลอดภัยสูง'; strengthText.style.color = '#00ff66'; } checkMatch(); }); confirmInput.addEventListener('input', checkMatch); function checkMatch() { const p1 = passwordInput.value; const p2 = confirmInput.value; if (p2.length === 0) { matchBadge.textContent = ''; } else if (p1 === p2) { matchBadge.textContent = '✓ รหัสผ่านตรงกัน'; matchBadge.style.color = '#00ff66'; } else { matchBadge.textContent = '✕ รหัสผ่านยังไม่ตรงกัน'; matchBadge.style.color = '#ff3366'; } } </script> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.25 |
proxy
|
phpinfo
|
Settings