Please help start in the right way . I want to add ‘if user is online’ system. Which I will use to prevent multiple logins under 1 name, also this system will add option to users showing them who is online at the moment.
I understand that I need mysql table where I will store online users. But how can I understand each second if user is still here? if he logs out then ok, it’s easy, but if he will restart? or something else ? So how can I controll all users and understand per second their status ?
UPDATE After some discussions with Cupcake I decided to have only who’s online feature, letting 1 user to log in multiple times, cause it’s difficult to prevent him from doing that in a comfortable way.
What you could do, which is what I sometimes do, is this, in the user table have a column named
session_hashor something similar.And each time the user logs in, generate a new session hash yourself or use the
session_idPHP has, as long as you usesession_starton each page.Then to retrieve the users row from the database, have a cookie with that session_hash.
Example
Login form
PHP page does the following
Then on each page do the following
What all this does if lets the user choose if they want to be remembered each visit, if they do create a cookie that doesn’t expire for at least a month that way they will be remembered next time they come to the site, but if they login from another browser or computer the “salt” won’t be valid on the other computer.