بالطبع! إليك نسخة مُحسَّنة من صفحة التسجيل (Sign Up) باللغة الإنجليزية مع:
- تصميم عصري (Modern & Sleek)
- وضع الدارك مود (Dark Mode Toggle)
- زر تسجيل دخول عبر Google (Google Sign-In Button)
- رابط لتسجيل الدخول إذا كان لدى المستخدم حساب بالفعل
- تأثيرات تفاعلية وحركات خفيفة باستخدام CSS Transitions
✅ النتيجة: تصميم جذاب + Dark Mode + تسجيل عبر Google
💡 يمكنك حفظ هذا الكود في ملف باسم register.php
<?php
session_start();
require 'db.php'; // Make sure this file exists and connects to your DB
$error_message = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
if (empty($username) || empty($email) || empty($password)) {
$error_message = "All fields are required.";
} elseif (strlen($username) < 3) {
$error_message = "Username must be at least 3 characters long.";
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_message = "Invalid email format. Please check your email.";
} elseif (strlen($password) < 8) {
$error_message = "Password must be at least 8 characters long.";
} else {
$password_hash = password_hash($password, PASSWORD_DEFAULT);
try {
$stmt = $pdo->prepare("INSERT INTO users (username, email, password_hash) VALUES (?, ?, ?)");
$stmt->execute([$username, $email, $password_hash]);
$_SESSION['user_id'] = $pdo->lastInsertId();
header("Location: task.php");
exit;
} catch (PDOException $e) {
if (strpos($e->getMessage(), 'Duplicate entry') !== false) {
if (strpos($e->getMessage(), 'username') !== false) {
$error_message = "This username is already taken.";
} elseif (strpos($e->getMessage(), 'email') !== false) {
$error_message = "This email is already registered.";
}
} else {
$error_message = "An error occurred during registration.";
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Create Account</title>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
<style>
:root {
--bg-color: #f5f7fa;
--card-bg: #ffffff;
--text-color: #2d3436;
--input-bg: #f1f2f6;
--primary-color: #6c63ff;
--primary-hover: #5a54e3;
--dark-bg: #1e1e2f;
--dark-card: #2c2c3e;
--dark-text: #f1f1f1;
--font-family: 'Poppins', sans-serif;
}
body.dark {
--bg-color: #1e1e2f;
--card-bg: #2c2c3e;
--text-color: #f1f1f1;
--input-bg: #3b3b4f;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: var(--font-family);
background-color: var(--bg-color);
color: var(--text-color);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
transition: background-color 0.3s ease;
}
.registration-card {
background-color: var(--card-bg);
padding: 50px;
border-radius: 16px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
max-width: 450px;
width: 100%;
text-align: center;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.registration-card:hover {
transform: translateY(-5px);
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.12);
}
h2 {
font-size: 2rem;
margin-bottom: 10px;
color: var(--primary-color);
}
p.subtitle {
font-size: 1rem;
color: #888;
margin-bottom: 30px;
}
form {
display: flex;
flex-direction: column;
gap: 18px;
}
input {
width: 100%;
padding: 16px 20px;
border: none;
border-radius: 10px;
background-color: var(--input-bg);
font-size: 1rem;
outline: none;
transition: all 0.3s ease;
}
input:focus {
box-shadow: 0 0 0 4px rgba(108, 99, 255, 0.2);
background-color: #fff;
}
button[type="submit"] {
padding: 16px;
background-color: var(--primary-color);
color: white;
font-weight: bold;
border: none;
border-radius: 10px;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.1s ease;
}
button[type="submit"]:hover {
background-color: var(--primary-hover);
transform: translateY(-3px);
}
.google-login {
margin-top: 20px;
padding: 14px;
background-color: #dd4b39;
color: white;
border: none;
border-radius: 10px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.google-login:hover {
background-color: #cc0000;
}
.toggle-dark {
position: absolute;
top: 20px;
right: 20px;
background: transparent;
border: 1px solid #ccc;
padding: 10px 15px;
border-radius: 8px;
cursor: pointer;
font-size: 0.9rem;
}
.login-link {
margin-top: 20px;
font-size: 0.95rem;
}
.login-link a {
color: var(--primary-color);
text-decoration: none;
font-weight: 600;
}
.error-message {
background-color: #ffebee;
color: #c62828;
padding: 12px;
border-radius: 10px;
margin-bottom: 20px;
font-size: 0.9rem;
border: 1px solid #ffcdd2;
}
@media (max-width: 500px) {
.registration-card {
padding: 40px 20px;
border-radius: 0;
box-shadow: none;
width: 100%;
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
}
}
</style>
</head>
<body>
<button class="toggle-dark" onclick="toggleDarkMode()">Toggle Dark Mode</button>
<div class="registration-card">
<h2>Create Your Account</h2>
<p class="subtitle">A modern design with smooth interactions and dark mode support.</p>
<?php if ($error_message): ?>
<div class="error-message"><?= htmlspecialchars($error_message) ?></div>
<?php endif; ?>
<form method="POST">
<input type="text" name="username" placeholder="Username" required value="<?= htmlspecialchars($_POST['username'] ?? '') ?>">
<input type="email" name="email" placeholder="Email Address" required value="<?= htmlspecialchars($_POST['email'] ?? '') ?>">
<input type="password" name="password" placeholder="Password" required>
<button type="submit">Sign Up</button>
</form>
<button class="google-login">Sign In with Google</button>
<div class="login-link">
Already have an account? <a href="login.php">Log in here</a>
</div>
</div>
<script>
function toggleDarkMode() {
document.body.classList.toggle('dark');
}
</script>
</body>
</html>
🔧 الميزات الجديدة:
| الميزة | الوصف |
|---|
| 🌙 الدارك مود | زر Toggle Dark Mode يُغيّر بين الوضع العادي والداكن باستخدام CSS Variables |
| 🧠 حركات تفاعلية | مثل تحريك الزر عند hover، ظهور تدريجي للحقول، وظل البطاقة عند hover |
| 🟡 زر تسجيل عبر Google | تم إضافة زر بصري فقط (Sign In with Google) – يمكنك ربطه بـ Google OAuth لاحقاً |
| 🔗 رابط تسجيل دخول | لوحة تحتوي على رابط إلى صفحة login.php للمستخدمين الذين لديهم حساب |
| 📱 متجاوب (Responsive) | التصميم يتكيف مع الشاشات الصغيرة |
✅ ما يجب أن تضيفه لاحقًا:
- OAuth Google Login: باستخدام Google Sign-In API
- Validation رسومية أفضل: مثل رمز الخطأ أو التحقق الفوري أثناء الكتابة
- تحديث قاعدة البيانات: لإضافة حقل
provider في حال التسجيل عبر Google
هل ترغب أن أساعدك في إضافة Google OAuth أو تحويل الصفحة إلى Bootstrap 5؟