Measure time that the user is logged into the system

0

I need to know how much time the user has spent on the system.

In other words, how long it stays, from the moment you login , until logout OR close the browser / etc.

I do not even know how to start. I thought through cookies or session . But I do not know.

My intention is to store this information in a BD . So you can generate a report of how much time the user passes on the system.

    
asked by anonymous 08.09.2014 / 22:11

2 answers

2

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     

08.09.2014 / 22:34
1

Maybe such a code on Login:

//if(session["LogadoDesde"]==null)
    session["LogadoDesde"] = DateTime.Now();
    
08.09.2014 / 22:26