File manager - Edit - /home/webapp69.cm.in.th/u69319090001/Shop 001/register.php
Back
<?php /** * หน้าสมัครสมาชิกสำหรับลูกค้า (Customer Registration) * REDSHOP Pre-order System */ session_start(); require_once 'db.php'; // หากเข้าสู่ระบบอยู่แล้ว ให้เปลี่ยนเส้นทางไปหน้าแรก if (isset($_SESSION['user_id'])) { header("Location: index.php"); exit; } $error_msg = ''; $name = ''; $phone = ''; $email = ''; $address = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = isset($_POST['name']) ? trim($_POST['name']) : ''; $phone = isset($_POST['phone']) ? trim($_POST['phone']) : ''; $email = isset($_POST['email']) ? trim($_POST['email']) : ''; $address = isset($_POST['address']) ? trim($_POST['address']) : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; $confirm_password = isset($_POST['confirm_password']) ? $_POST['confirm_password'] : ''; if (empty($name) || empty($phone) || empty($password)) { $error_msg = "กรุณากรอกข้อมูลที่มีเครื่องหมาย * ให้ครบถ้วน"; } elseif (!preg_match("/^[0-9]{9,10}$/", $phone)) { $error_msg = "รูปแบบเบอร์โทรศัพท์ไม่ถูกต้อง (กรุณากรอกตัวเลข 9-10 หลัก)"; } elseif (!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL)) { $error_msg = "รูปแบบอีเมลไม่ถูกต้อง"; } elseif (strlen($password) < 6) { $error_msg = "รหัสผ่านต้องมีความยาวอย่างน้อย 6 ตัวอักษร"; } elseif ($password !== $confirm_password) { $error_msg = "รหัสผ่านและยืนยันรหัสผ่านไม่ตรงกัน"; } else { try { // ตรวจสอบว่าเบอร์โทรศัพท์นี้ถูกใช้งานหรือยัง $stmt = $pdo->prepare("SELECT id FROM users WHERE phone = :phone LIMIT 1"); $stmt->execute(['phone' => $phone]); if ($stmt->fetch()) { $error_msg = "เบอร์โทรศัพท์นี้ลงทะเบียนในระบบแล้ว กรุณาเข้าสู่ระบบ"; } else { // หากกรอกอีเมล ตรวจสอบว่าอีเมลซ้ำหรือไม่ if (!empty($email)) { $stmt_email = $pdo->prepare("SELECT id FROM users WHERE email = :email LIMIT 1"); $stmt_email->execute(['email' => $email]); if ($stmt_email->fetch()) { $error_msg = "อีเมลนี้ลงทะเบียนในระบบแล้ว กรุณาใช้อีเมลอื่นหรือเข้าสู่ระบบ"; } } if (empty($error_msg)) { // เข้ารหัสผ่านด้วย Bcrypt $password_hash = password_hash($password, PASSWORD_BCRYPT); $email_val = !empty($email) ? $email : null; $insert = $pdo->prepare("INSERT INTO users (name, phone, email, password, address) VALUES (:name, :phone, :email, :password, :address)"); $insert->execute([ 'name' => $name, 'phone' => $phone, 'email' => $email_val, 'password' => $password_hash, 'address' => $address ]); $_SESSION['register_success'] = "สมัครสมาชิกเรียบร้อยแล้ว! สามารถเข้าสู่ระบบได้ทันที"; header("Location: login.php"); exit; } } } catch (PDOException $e) { $error_msg = "เกิดข้อผิดพลาดในการบันทึกข้อมูล: " . $e->getMessage(); } } } ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>สมัครสมาชิก - REDSHOP Pre-order</title> <!-- Google Fonts --> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&family=Noto+Sans+Thai:wght@300;400;500;700&display=swap" rel="stylesheet"> <!-- Bootstrap 5 CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <!-- FontAwesome --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <style> :root { --primary-red: #e61e2b; --hover-red: #c1101b; --light-red: #ffebeb; --dark-gray: #2d3748; --light-gray: #f7fafc; } body { font-family: 'Noto Sans Thai', 'Inter', sans-serif; background: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 30px 15px; } .auth-card { background: #ffffff; border-radius: 24px; box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08); border: 1px solid rgba(230, 30, 43, 0.1); overflow: hidden; width: 100%; max-width: 500px; } .auth-header { background: linear-gradient(135deg, var(--primary-red) 0%, #ff5252 100%); color: #fff; padding: 2.5rem 2rem 2rem; text-align: center; position: relative; } .auth-header::after { content: ''; position: absolute; bottom: -15px; left: 50%; transform: translateX(-50%); width: 30px; height: 30px; background: #fff; clip-path: polygon(50% 100%, 0 0, 100% 0); } .auth-header h3 { font-weight: 700; font-size: 1.6rem; margin-bottom: 0.25rem; } .auth-header p { font-size: 0.9rem; opacity: 0.9; margin-bottom: 0; } .auth-body { padding: 2.5rem 2rem 2rem; } .form-label { font-weight: 600; font-size: 0.9rem; color: var(--dark-gray); margin-bottom: 6px; } .input-group-text { background-color: #f8fafc; border-color: #e2e8f0; color: #718096; border-radius: 12px 0 0 12px; } .form-control { border-radius: 0 12px 12px 0; padding: 12px 14px; border-color: #e2e8f0; font-size: 0.95rem; } .form-control:focus { border-color: var(--primary-red); box-shadow: 0 0 0 3px rgba(230, 30, 43, 0.15); } textarea.form-control { border-radius: 12px; } .btn-red { background-color: var(--primary-red); color: #fff; font-weight: 600; border: none; padding: 12px; border-radius: 12px; width: 100%; transition: all 0.2s ease; box-shadow: 0 4px 12px rgba(230, 30, 43, 0.25); } .btn-red:hover { background-color: var(--hover-red); color: #fff; transform: translateY(-1px); box-shadow: 0 6px 16px rgba(230, 30, 43, 0.35); } .auth-footer { text-align: center; padding: 0 2rem 2rem; font-size: 0.9rem; color: #718096; } .auth-footer a { color: var(--primary-red); text-decoration: none; font-weight: 600; } .auth-footer a:hover { text-decoration: underline; } .brand-link { display: inline-block; margin-bottom: 1rem; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.2rem; } </style> </head> <body> <div class="auth-card"> <div class="auth-header"> <a href="index.php" class="brand-link"> <i class="fa-solid fa-cart-shopping-fast me-2"></i>REDSHOP </a> <h3>สมัครสมาชิกใหม่</h3> <p>กรอกข้อมูลเพื่อรับสิทธิพิเศษและติดตามสถานะการจอง</p> </div> <div class="auth-body"> <?php if (!empty($error_msg)): ?> <div class="alert alert-danger alert-dismissible fade show py-2" style="font-size: 0.9rem;" role="alert"> <i class="fa-solid fa-circle-exclamation me-2"></i><?php echo $error_msg; ?> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> </div> <?php endif; ?> <form action="register.php" method="POST"> <div class="mb-3"> <label for="name" class="form-label">ชื่อ-นามสกุล <span class="text-danger">*</span></label> <div class="input-group"> <span class="input-group-text"><i class="fa-solid fa-user"></i></span> <input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($name); ?>" placeholder="เช่น สมชาย ใจดี" required autofocus> </div> </div> <div class="mb-3"> <label for="phone" class="form-label">เบอร์โทรศัพท์ (ใช้เป็น ID เข้าสู่ระบบ) <span class="text-danger">*</span></label> <div class="input-group"> <span class="input-group-text"><i class="fa-solid fa-phone"></i></span> <input type="tel" class="form-control" id="phone" name="phone" value="<?php echo htmlspecialchars($phone); ?>" pattern="[0-9]{9,10}" placeholder="เช่น 0891234567 (9-10 หลัก)" required> </div> </div> <div class="mb-3"> <label for="email" class="form-label">อีเมล <span class="text-muted fw-normal">(ไม่บังคับ)</span></label> <div class="input-group"> <span class="input-group-text"><i class="fa-solid fa-envelope"></i></span> <input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" placeholder="your@email.com"> </div> </div> <div class="row g-2 mb-3"> <div class="col-md-6"> <label for="password" class="form-label">รหัสผ่าน <span class="text-danger">*</span></label> <div class="input-group"> <span class="input-group-text"><i class="fa-solid fa-lock"></i></span> <input type="password" class="form-control" id="password" name="password" minlength="6" placeholder="ขั้นต่ำ 6 ตัวอักษร" required> </div> </div> <div class="col-md-6"> <label for="confirm_password" class="form-label">ยืนยันรหัสผ่าน <span class="text-danger">*</span></label> <div class="input-group"> <span class="input-group-text"><i class="fa-solid fa-lock"></i></span> <input type="password" class="form-control" id="confirm_password" name="confirm_password" minlength="6" placeholder="ยืนยันอีกครั้ง" required> </div> </div> </div> <div class="mb-4"> <label for="address" class="form-label">ที่อยู่สำหรับจัดส่งสินค้า <span class="text-muted fw-normal">(บันทึกไว้ใช้งาน)</span></label> <textarea class="form-control" id="address" name="address" rows="2" placeholder="บ้านเลขที่, ถนน, ตำบล, อำเภอ, จังหวัด, รหัสไปรษณีย์"><?php echo htmlspecialchars($address); ?></textarea> </div> <button type="submit" class="btn btn-red mb-3"> <i class="fa-solid fa-user-plus me-2"></i>ยืนยันการสมัครสมาชิก </button> <div class="text-center"> <a href="index.php" class="text-muted small text-decoration-none"> <i class="fa-solid fa-arrow-left me-1"></i> กลับหน้าหลักร้านค้า </a> </div> </form> </div> <div class="auth-footer border-top pt-3"> มีบัญชีสมาชิกอยู่แล้ว? <a href="login.php">เข้าสู่ระบบทันที</a> </div> </div> <!-- Bootstrap JS --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.25 |
proxy
|
phpinfo
|
Settings