From the description you gave, I imagine you do not save a session, much less cookie, and leaving the site you should log in again. So I present a simple example of 2 tables.
USERS
ID | NOME | SENHA | EMAIL...
1 | Papa Charlie | ***** | [email protected]
USER-LOGIN
ID | ID_USER | LOGIN_TIME | LAST_LOGIN
1 | 1 | 07/09/2014 11:00 | 07/09/2014 12:00 // login ontem
2 | 1 | 08/09/2014 13:00 | 08/09/2014 17:00 // login hoje
1) When the user logs in to the site, save the last updated hour in your USER-LOGIN DB. At each login, a record is entered in USER-LOGIN
, and each request is updated.
In the example above, yesterday's login lasted 1 hour (11 am) and today's login lasted 4 hours (4 pm)
2) The next step would be to send a request via js to update the field.
setTimeout(function(){
$.get("check_user.php");
} 60000 );
Every minute the check_user.php
page will receive the user data and update the LAST_LOGIN