Use an ajax call to php web page/service which update your database, it’s better if you can store log in and log out time and get the duration spent on site using a query.
This ( http://satoewarna.com/jqsajax/ ) will help you in calling PHP method from javascript.
solved Counting number of seconds spent on site by specific user and store in mysql