What are common methods for handling online/offline status indicators for users in PHP applications?

One common method for handling online/offline status indicators for users in PHP applications is to store the user's status in a database and update it when the user logs in or out. This way, other users can see the current online status of each user in real-time.

// Update user status to online when user logs in
function updateStatusToOnline($userId) {
    // Update user status in the database to online
    // Example SQL query: UPDATE users SET status = 'online' WHERE id = $userId
}

// Update user status to offline when user logs out
function updateStatusToOffline($userId) {
    // Update user status in the database to offline
    // Example SQL query: UPDATE users SET status = 'offline' WHERE id = $userId
}

// Check if a user is online
function isUserOnline($userId) {
    // Query the database to check the user's status
    // Example SQL query: SELECT status FROM users WHERE id = $userId
    // Return true if status is 'online', false otherwise
}