false, 'error' => 'Invalid profile_id']); exit; } $stmt = $pdo->prepare("SELECT id FROM profiles WHERE id = ? AND user_id = ?"); $stmt->execute([$profile_id, $user_id]); if (!$stmt->fetchColumn()) { http_response_code(403); echo json_encode(['success' => false, 'error' => 'Profile not allowed']); exit; } $_SESSION['active_profile_id'] = $profile_id; echo json_encode(['success' => true, 'active_profile_id' => $profile_id]);