you can track him using js, for example when the user leaves the page or closes the browser, with js you can trigger an ajax call when this happens
to do this you must listen to onunload event, with jquery its implementation is super easy
$( window ).on( 'unload', function() {
$.ajax( '/user/is-leaving' );
} );
note that you not need to listen a sucess ajax event, just send the request to the server
So I'm hoping this thread will help others out there as well as myself. I also took a look into using event listerns so I found this :
Event::listen('auth.logout', function($user)
{
// Will log the user out like it normally would
// Take the time stamp from the login in time
// Then subtract it from the current time stamp
// Then with the difference add that to the total time logged in for the user
});
My only issue now is does the auth.logout event get fired when a user clicks on the close button for the browser? I guess a way to test for this would be to listen for the auth.logout event, and if it fires then have an email sent to me (just for testing purposes) to make sure that even closing the browser will end the session + fire the event.
arcollector said:
you can track him using js, for example when the user leave the page or close the browser, with js you can trigger an ajax call
to do this you must listen to onunload, with jquey its implemention is super trivial
$( window ).on( 'unload', function() { $.ajax( '/user/is-leaving' ); } );
note that you not need to listen a sucess ajax event, just send the request to the server
I'm going to take a look at if this is a cross browser solution. If it is then you just saved me a lot of time!
The answer to the second question is no. Auth has no knowledge if a user closes the window.
I would go with the ajax route as well.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community