i am checking on the user status - whether he is active or idle - in a web page (in a pop up window). in case he is idle for more than 30 minutes, the window will automatically close and reset some flags in the database.
i set cookies containing the time-in (the time he opens the pop-up window) and check it against the current time every time the page refreshes or he navigates to another page (still in the pop-up window). aside from the cookies, i also set the time-in in the database (in case the pop-up window isn't open, a cron job will take care of the resetting of flags by checking the time-in in the database).
there might be a case that he is typing something in the window and no page load occurs within 30 minutes so the window will automatically close and he will lose his work. so i added a function so that each onkeydown and onclick event, the time-in value in both the cookie and the database will be updated.
also, there can be more than one person who is using the system.
will this consume too many resources? i'm not familiar with stuff related to this issue. or is there a better way to do this?
thanks!
If you send ever onkeypress and every onclick event to the server/database, this will penetrate your server! For these two things I would add another javascript function which sends information if the user is active in an interval of - for example - 2 or 5 minutes. You can do this by setInterval or setTimeout functions and track, if the user was active in the last period. If he was, send the request, if not, don't send.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With