0

I am programming a c# application.

I used php for my server side and mysql database for keep accounts data.I can access my mysql database by WebRequest and POST method. I update account status by login to prevent other ones login but i do not know how to know user exit time.

I know i can program c# for exit event but what if user exit unexpectedly.It seems a little risky because if i exit with a special condition user will be logged and no one can login even last user so i think its better to set a expire time in server side.

I update my user status in a time range but how can i program my database to change a record when there is no user update?Can i do it by php?SQL queries?

Thanks.

  • Use expire when timed out strategy instead of destroy when exit strategy. As you know, the app can closed without any related events. –  Jul 04 '20 at 05:34
  • In your server, add a datetime which recording the user was last vaildated time. And client pinging to validate its connection in some interval. Then, the server can monitoring the datetimes to determine which users should unloaded from memory. –  Jul 04 '20 at 05:57
  • @donggas90 Thanks that is a nice solution – Amirmohammad Farhang Jul 04 '20 at 06:48

3 Answers3

0

In C# you can track form close event or user logout. Therefore you can track user exit. Consider Activated event and/or LostFocus event as you can do nothing more if user exits unexpectedly as if the PC lost power.

sheR
  • 387
  • 2
  • 8
0

In php you can use session to keep the user's status. I would recommend setting a number of the number of active sessions based on your question so that if someone tries to login else where they would get an error or the they managed to login the other active user would automatically log out

  • Use php session?So, this will expire in 24 min after last update?Is it secure enough?Can i update database records by session expire? – Amirmohammad Farhang Jul 04 '20 at 05:45
  • Php sessions can last as long as you tell them to last and can be as secure as you make it to be. For a beginner in my opinion, no, but there are tutorials on the web to help you secure it. You generate a token and store in the database if you want. Here is a resource to help you expire the session: https://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes – Koffivi V. Woglo Jul 04 '20 at 05:56
  • Thanks and can i command to do something when sessions expire? – Amirmohammad Farhang Jul 04 '20 at 06:47
  • Yes sir, you can – Koffivi V. Woglo Jul 04 '20 at 13:10
0

I think you can try this with TRIGGER in Database to track idle time and logout user from database. If user was idle on the screen you can update Database with in the time interval you defined in trigger from UI.

CREATE
    [DEFINER = user]
    TRIGGER trigger_name
    trigger_time trigger_event
    ON tbl_name FOR EACH ROW
    [trigger_order]
    trigger_body

trigger_time: { BEFORE | AFTER }

trigger_event: { INSERT | UPDATE | DELETE }

trigger_order: { FOLLOWS | PRECEDES } other_trigger_name

For More info

MMM
  • 3,132
  • 3
  • 20
  • 32