File manager - Edit - /home/webapp69.cm.in.th/u69319090044/shop/register.php
Back
<?php // register.php - User registration page require_once 'includes/helper.php'; require_once 'classes/User.php'; start_secure_session(); // Redirect if already logged in if (isset($_SESSION['user_id'])) { header("Location: index.php"); exit(); } $error = ''; $success = ''; $csrfToken = generate_csrf_token(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = trim($_POST['username'] ?? ''); $password = trim($_POST['password'] ?? ''); $email = trim($_POST['email'] ?? ''); $firstName = trim($_POST['first_name'] ?? ''); $lastName = trim($_POST['last_name'] ?? ''); $token = $_POST['csrf_token'] ?? ''; // Validate CSRF if (!validate_csrf_token($token)) { $error = "ระบบความปลอดภัย: CSRF Token ไม่ถูกต้อง"; } else if (empty($username) || empty($password) || empty($email) || empty($firstName) || empty($lastName)) { $error = "กรุณากรอกข้อมูลให้ครบถ้วนทุกช่อง"; } else if (strlen($password) < 6) { $error = "รหัสผ่านต้องมีความยาวอย่างน้อย 6 ตัวอักษร"; } else { $userObj = new User(); try { // Check if user already exists $db = Database::getInstance()->getConnection(); $stmt = $db->prepare("SELECT id FROM users WHERE username = ? OR email = ?"); $stmt->execute([$username, $email]); if ($stmt->fetch()) { $error = "ชื่อผู้ใช้หรืออีเมลนี้มีอยู่ในระบบแล้ว"; } else { // Register using BCRYPT password hashing if ($userObj->register($username, $password, $email, $firstName, $lastName)) { $success = "สมัครสมาชิกสำเร็จเรียบร้อย! กรุณาเข้าสู่ระบบ"; } else { $error = "เกิดข้อผิดพลาดในการสมัครสมาชิก กรุณาลองใหม่อีกครั้ง"; } } } catch (Exception $e) { $error = "ข้อผิดพลาดระบบ: " . $e->getMessage(); } } } require_once 'includes/header.php'; ?> <div class="max-w-md mx-auto my-4 sm:my-8"> <div class="glass p-6 sm:p-8 rounded-2xl sm:rounded-3xl shadow-2xl relative overflow-hidden"> <!-- Decoration light glow --> <div class="absolute -top-12 -right-12 w-32 h-32 bg-violet-600/20 rounded-full blur-2xl"></div> <h2 class="text-3xl font-extrabold text-white mb-2 text-center tracking-tight">สมัครสมาชิก</h2> <p class="text-slate-400 text-sm text-center mb-8">ลงทะเบียนบัญชีใหม่เพื่อเริ่มการซื้อสินค้า</p> <?php if ($error): ?> <div class="bg-red-950/60 border border-red-800 text-red-300 p-4 rounded-xl text-sm mb-6 animate-pulse"> ⚠️ <?= escape($error) ?> </div> <?php endif; ?> <?php if ($success): ?> <div class="bg-emerald-950/60 border border-emerald-800 text-emerald-300 p-4 rounded-xl text-sm mb-6 text-center"> 🎉 <?= escape($success) ?> <div class="mt-3"> <a href="login.php" class="inline-block bg-violet-600 hover:bg-violet-500 text-white font-semibold text-xs px-4 py-2 rounded-lg transition-all">ไปที่หน้าเข้าสู่ระบบ →</a> </div> </div> <?php endif; ?> <?php if (!$success): ?> <form action="register.php" method="POST" class="space-y-4"> <input type="hidden" name="csrf_token" value="<?= escape($csrfToken) ?>"> <div class="grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4"> <div> <label for="first_name" class="block text-xs font-semibold uppercase tracking-wider text-slate-400 mb-1.5">ชื่อจริง</label> <input type="text" name="first_name" id="first_name" required class="w-full px-4 py-2.5 bg-slate-900 border border-slate-800 focus:border-violet-500 rounded-xl focus:ring-1 focus:ring-violet-500 outline-none text-slate-100 placeholder-slate-600 transition-all text-sm" placeholder="สมชาย"> </div> <div> <label for="last_name" class="block text-xs font-semibold uppercase tracking-wider text-slate-400 mb-1.5">นามสกุล</label> <input type="text" name="last_name" id="last_name" required class="w-full px-4 py-2.5 bg-slate-900 border border-slate-800 focus:border-violet-500 rounded-xl focus:ring-1 focus:ring-violet-500 outline-none text-slate-100 placeholder-slate-600 transition-all text-sm" placeholder="ใจดี"> </div> </div> <div> <label for="email" class="block text-xs font-semibold uppercase tracking-wider text-slate-400 mb-1.5">อีเมล (Email)</label> <input type="email" name="email" id="email" required class="w-full px-4 py-2.5 bg-slate-900 border border-slate-800 focus:border-violet-500 rounded-xl focus:ring-1 focus:ring-violet-500 outline-none text-slate-100 placeholder-slate-600 transition-all text-sm" placeholder="somchai@example.com"> </div> <div> <label for="username" class="block text-xs font-semibold uppercase tracking-wider text-slate-400 mb-1.5">ชื่อผู้ใช้งาน (Username)</label> <input type="text" name="username" id="username" required class="w-full px-4 py-2.5 bg-slate-900 border border-slate-800 focus:border-violet-500 rounded-xl focus:ring-1 focus:ring-violet-500 outline-none text-slate-100 placeholder-slate-600 transition-all text-sm" placeholder="เลือกชื่อผู้ใช้งาน"> </div> <div> <label for="password" class="block text-xs font-semibold uppercase tracking-wider text-slate-400 mb-1.5">รหัสผ่าน (Password)</label> <input type="password" name="password" id="password" required class="w-full px-4 py-2.5 bg-slate-900 border border-slate-800 focus:border-violet-500 rounded-xl focus:ring-1 focus:ring-violet-500 outline-none text-slate-100 placeholder-slate-600 transition-all text-sm" placeholder="ขั้นต่ำ 6 ตัวอักษร"> </div> <button type="submit" class="w-full py-3 bg-gradient-to-r from-violet-600 to-indigo-600 hover:from-violet-500 hover:to-indigo-500 text-white font-semibold rounded-xl shadow-lg shadow-violet-600/35 transition-all duration-200 text-sm"> ยืนยันสมัครสมาชิก 👤 </button> </form> <?php endif; ?> <div class="mt-6 pt-4 border-t border-slate-900 text-center text-xs text-slate-500"> มีบัญชีผู้ใช้อยู่แล้ว? <a href="login.php" class="text-violet-400 font-semibold hover:text-violet-300">เข้าสู่ระบบที่นี่</a> </div> </div> </div> <?php require_once 'includes/footer.php'; ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.25 |
proxy
|
phpinfo
|
Settings