What are the potential drawbacks of using timestamps to determine user online status in PHP?

One potential drawback of using timestamps to determine user online status in PHP is that it may not accurately reflect the user's actual online status if the user forgets to update the timestamp when they log out. To solve this issue, you can implement a session-based approach where the user's online status is determined by the presence of an active session.

// Check if user has an active session to determine online status
session_start();

if(isset($_SESSION['user_id'])){
    echo "User is online";
} else {
    echo "User is offline";
}