Hi to all,
I have a request from client to catch browser closing and log in DB table user id and session lenght.
My CI version is 2.1.1 that has in config sess_expire_on_close, but in system/libraries/Session.php variable sess_expire_on_close is just mentioned as parameter and I can’t find any further use in file.
Can someone guide me how to catch browser closing and bind callback to it ?
Not possible. While you can warn a person that they are navigating away from the page and may lose what they were working on, there’s no way to do what your client is asking.
You might search for onbeforeunload, which is a javascript method. This is as close as you can get to an event for browser close, but it’s going to give the site visitor a confirmation, and they can click yes or cancel.
A solution might be to implement some javascript that pings the server with the user’s ID every 30 or 60 seconds, however, this might be expensive if you have a lot of users.