Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should be table structure to maintain login logout logs?

I have loginlog table as following

Field       Type
login_id    int(10)     NOT NULL
platform    varchar(50) NOT NULL
browser     varchar(50) NOT NULL
ipaddress   varchar(50) NOT NULL
last_login  datetime    NULL
last_logout datetime    NULL

But on this structure I am confuse that I can add login time but its hard to update it for logout time. I have not added primary key because logs are frequent and primarykey will soon reach it max value. What should be the best way? Please help.

like image 587
Rajan Rawal Avatar asked Oct 17 '25 21:10

Rajan Rawal


1 Answers

Having a single row with both login and logout like that is just asking for trouble, because it assumes that every login has a corresponding logout, which is just not the case. Sometimes they will login on a public computer and never log out, sometimes they will open an anonymous window and login.

Instead, I would cut it down to just a type:

  • login_id
  • platform
  • browser
  • ip_address
  • date
  • type (login / logout)
like image 197
kingcoyote Avatar answered Oct 20 '25 11:10

kingcoyote



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!