How to make status online/offline in php?

registration, authorization, questionnaire and its editing, a list of all users and something else have already been done. Question: how to make status online/offline in php? At least tell me which way to think.


Answer 1, authority 100%

I do this: when a user navigates to any page on the site, I execute a query to the users table, which has a lastvisittimefield, and every time the user navigates to any page, I update this value with the current time() value. Checking online / offline is performed by a selection of the type

$sql=mysql_query("SELECT lastvisittime FROM users WHERE lastvisittime>". time()-300 ." WHERE userid=".$userid);
if ($row=mysql_fetch_array($sql))
{
$online=true;
}

something like that. in this version, sessions are not needed.