I want to make a user status system and i was thinking to have in my database a datetime field called last_active and update that field automatically with ajax with current time.
Then i check minutes between last_active and current time.. to tell if the user is online, inactive and offline..
Is this a good technique? and what happens if the user for example has the site open but is doing something else?
Is there a way to fire ajax request only if the user is viewing the page?
Your current method is a good technique to do, and the way to go,
you can check with
focusinandfocusoutfunction with jquery to check if user is currently active on document or not,you should take variable that will set to
trueinfocusinfunction and, will set tofalseinfocusoutfunction. now the continues ajax request function will fire only if the variable is set totrue.