prepare("SELECT * FROM users WHERE username = ?"); $stmt->execute([$username]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password'])) { // Get user roles $roles_stmt = $pdo->prepare("SELECT r.role_name FROM user_roles ur JOIN roles r ON ur.role_id = r.id WHERE ur.user_id = ?"); $roles_stmt->execute([$user['id']]); $roles = $roles_stmt->fetchAll(PDO::FETCH_COLUMN); // Store user info in session $_SESSION['user_id'] = $user['id']; $_SESSION['username'] = $user['username']; $_SESSION['email'] = $user['email']; $_SESSION['user_roles'] = $roles; // Redirect based on role if (in_array('Admin', $roles)) { header('Location: admin.php'); } else { header('Location: index.php'); } exit; } else { $error = 'Invalid username or password.'; } } } ?>

Login

Don't have an account? Register here.