What are the limitations of using the "last accessed" timestamp to determine user online status in PHP?

The limitations of using the "last accessed" timestamp to determine user online status in PHP include the fact that it may not accurately reflect real-time activity, as the user could have closed the browser without logging out. To solve this issue, we can implement a session-based approach where the user's online status is updated when they log in and destroyed when they log out.

// Start or resume session
session_start();

// Set user as online when they log in
$_SESSION['user_online'] = true;

// Update user online status when they log out
unset($_SESSION['user_online']);