0

i created a small application.in that application i want to store the log-in and log-out time.The user logged-in correctly but at the time of log-out the user directly closes the browser.how to store log-out time..

in my application i created a button log-out if the user click on the log-out button there is no problem.but the user closes the browser directly with out click on the log-out button.in this situation how to store the log-out time of a user.

plz help me..

sandeep
  • 375
  • 1
  • 2
  • 15

3 Answers3

2

If I am right, you cannot run any script when a user closes browser.

You could store the time into session: like

$_SESSION['LAST_REQUEST_TIME'] = time() ;

Each time the user updates a page on your website a new time is set.

Also, save the time into database, because session is destroyed once a user closes browser.

sybear
  • 7,837
  • 1
  • 22
  • 38
1

First of all: There is no reliable way to detect the user closing the browser (short of some allways-running ajax heartbeat). JavaScript is only a bit of help, as it won't catch browser crash, loss of network connectivity, etc.

That said, what you might really want is the timestamp of the last request in a login session - and this is trivial to get. You just update a last_seen timestamp on every request with a fitting session ID.

Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
0

You should store last request time to db and compare with the new request time and if it's greater than decided time (e.g. 15 min) you can ask for login.

Mohit Mehta
  • 1,283
  • 12
  • 21