Lets say that there is a webpage that can only be accessed by inputting a user name and password on a separate page. This webpage aside from its normal function, should also keep track of the time a user logs into it and the time when the user logs out.
The system I currently have in place is a JavaScript solution. A function to log logins with a successful click event on the submit button and a function to log logouts on the logout button.
A few problem here obviously. What if a user closes the browser? that logout wont be recorded. What if a user loses internet connection? etc etc. I can think a few use case scenerios of where a client side handler can get it wrong. I need something protected, something server side. What method do you guys recommend for accomplishing above task without the flaws of client side? Does a viable client side method exist?
With a websocket solution you could be noticed at serverside when new users connects or disconnects. The only “drawback” with this kind of solution, is that if the user go to another page (even in the same domain), then is like the user disconects. Then, it will “reconect” if in the new page is the same websocket solution to track user login.
You could avoid this by having an “ajax like” navigation, so the user never leaves a single page.
There are some cool APIs to implement websocket, like Pusher.
Here is the link to pusher