How can timestamps of user actions be utilized to determine online/offline status in PHP applications?

To determine online/offline status in PHP applications using timestamps of user actions, we can set a threshold time limit (e.g., 5 minutes) within which if a user has not performed any action, they are considered offline. By comparing the current time with the timestamp of the user's last action, we can determine their online status.

// Assuming $lastActionTimestamp is the timestamp of the user's last action
$threshold = 5 * 60; // 5 minutes in seconds
$currentTimestamp = time();

if (($currentTimestamp - $lastActionTimestamp) <= $threshold) {
    echo "User is online";
} else {
    echo "User is offline";
}