Today post I want to share a little idea to avoiding two or more different user login using the same user ID or username in one application, this feature might be implemented in some specific application that have many restriction and tracking of logged user action in the system. In this post I am not showing any full code to test, just my simple thought.
Users Table
The users table is most commonly used name in application, and the typical column name are id, username, password, first_name, last_name, etc. My idea is to adding one more field in users table that flagging if the user logged in or not. The simple SQL query might be something like this code below.
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`is_logged_id` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
The flag column in this example is is_logged_id field set to INT type with one length, this will only consist the value between 1 (user logged in) or 0 (user not logged in).