D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
skyconb
/
newsyacine
/
Filename :
login.php
back
Copy
<?php // =============================================== // login.php (معالج تسجيل الدخول) // =============================================== session_start(); include 'db_connect.php'; // تأكد من وجود ملف الاتصال بقاعدة البيانات $error = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) { $username = trim($_POST['username']); $password = $_POST['password']; if (empty($username) || empty($password)) { $error = "الرجاء إدخال اسم المستخدم وكلمة المرور."; } else { // 1. جلب بيانات المستخدم، بما في ذلك عمود 'admin' (الدور) $sql = "SELECT id, username, password, admin FROM users WHERE username = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param("s", $username); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows === 1) { $user = $result->fetch_assoc(); // 2. التحقق من كلمة المرور (باستخدام التشفير) if (password_verify($password, $user['password'])) { // تسجيل الدخول ناجح // 3. تخزين معلومات الجلسة الصحيحة $_SESSION['admin_logged_in'] = true; $_SESSION['admin_user_id'] = $user['id']; // 🎯 تخزين الدور بالاسم الصحيح (admin) من قاعدة البيانات $_SESSION['admin'] = $user['admin']; // 4. التوجيه إلى لوحة التحكم header("Location: admin.php"); exit(); } else { $error = "اسم المستخدم أو كلمة المرور غير صحيح."; } } else { $error = "اسم المستخدم أو كلمة المرور غير صحيح."; } $stmt->close(); } } ?> <!DOCTYPE html> <html lang="ar" dir="rtl"> <head> <meta charset="UTF-8"> <title>تسجيل دخول المسؤول</title> <style> /* CSS بسيط لصفحة الدخول */ body { font-family: Tahoma, sans-serif; background-color: #2c3e50; display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; } .login-box { background: white; padding: 30px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.2); width: 300px; text-align: center; } h2 { color: #2c3e50; margin-bottom: 20px; } .error-message { color: #e74c3c; margin-bottom: 15px; font-weight: bold; } input[type="text"], input[type="password"] { width: calc(100% - 20px); padding: 10px; margin-bottom: 15px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } button { width: 100%; padding: 10px; background-color: #f39c12; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; transition: background-color 0.3s; } button:hover { background-color: #e67e22; } </style> </head> <body> <div class="login-box"> <h2>تسجيل دخول المسؤول</h2> <?php if ($error): ?> <div class="error-message"><?php echo $error; ?></div> <?php endif; ?> <form method="POST"> <input type="text" name="username" placeholder="اسم المستخدم" required> <input type="password" name="password" placeholder="كلمة المرور" required> <button type="submit" name="login">تسجيل الدخول</button> </form> </div> </body> </html> <?php $conn->close(); ?>