I suppose you track users with cookies:
(or at least with a session id somewhere...)
Suppose the cookie expires in $expire seconds
(with $expire quite short - say 15 minutes:
so $expire = time() + 15 * 60)
each time the user connects $expire = time() + 15 * 60
you write the expire time along with the session ID in your database
at any time you can check if a session is expired (and the user is logged out)
by scanning the session database
this can be triggered by a cron job or by user connections.
(obviously you obtain logout time with a resolution of 15 minutes in this case)
look at the implementation of the Session_OnEnd event
in Apache::ASP for a good (IMHO) example.