Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As per my understanding of your question, you want to address following things:</p> <p>a. If for a given period of time, a user is inactive then he should be logged out and your database table gets updated. Here being inactive means, user has not used keyboard/mouse for a given period of time.</p> <p>b. If a user closes the browser without logging out, then he should be forcefully logged out and database table gets updated.</p> <p>Both these things can be accomplished using Javascript Functions and Ajax. Following is the flow which we have in our application for addressing above issues:</p> <ol> <li><p>Create a Javascript function, say logoutUser(), which will send an Ajax request for updating the database tables and destroying the session.</p></li> <li><p>Use Javascript function - setTimeOut - to call logoutUser() function after time period you have set for inactivity.</p></li> <li><p>Use Javascript events to catch mouse movement and keyboard activity and in every such event call use successively clearTimeOut (in order to remove the old time for execution of logoutUser()) and setTimeOut (for setting the new time of execution of logoutUser()). This way you would be able to catch the inactivity and logout the user after a period of time.</p></li> <li><p>For taking care of the issue related to closing of browser window use 'onbeforeunload' event of javascript and in this event send the Ajax request for updating the database tables.</p></li> </ol> <p>As our application uses ExtJS, thus, we have used ExtJs library functions to detect events. You can also prefer using some Javascript library for catching the events and implemeting the above solution.</p> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload