How can PHP be used to create effective ban-lists in forums, chat systems, and guestbooks without compromising user privacy?
Issue: When creating ban-lists in forums, chat systems, and guestbooks, it is important to maintain user privacy by not exposing sensitive information. One way to achieve this is by storing banned user IDs or IP addresses in a secure manner without revealing them to other users. PHP Code Snippet:
// Store banned user IDs in a secure manner
$banned_users = array(123, 456, 789);
// Check if user is banned before allowing access
$user_id = $_SESSION['user_id']; // Assuming user ID is stored in a session variable
if(in_array($user_id, $banned_users)) {
// Redirect or display a message to the user
header("Location: banned.php");
exit();
}