So, here is what i did:
I added a column to my users
table in my db, the column is called logged_in
, i set it to 1 whenever a user logs in, and i set it to 0 when the user logs out (and i then use this to show user's if their friends are online or not by checking that column for each of his/her friends).
I also have to keep the user logged in everytime he logs in until he manually logs out by clicking the logout button, which is why i am using cookies.
All of this would work great if the user always logged out by clicking the logout button on my website (or if somehow i was allowed to update the "logged_in" column in my db whenever a user clears their cookies (impossible) ).
So here is what leads to my problem:
Whenever the user deletes their cookies, then my code incorrectly reads their logged_in
column in my db as 1
although the user would be now logged out (which causes that user's friends to see him as "online" instead of "offline"), this bug persists until the user logs in and then logs out again manually (pressing the logout button), but it will occur everytime a user clears his cookies.
The reason i am not using anything time related (check for user activity every x
seconds) to auto login-logout users, is because i have to keep the user logged in.
So my problem finally:
Users Should Be Able To Logout Only By Manually Pressing The Logout Button On My Website. I Currently Achieve This By Keeping Them Logged In Using Cookies (So That They Can't Logout By Closing My Website Or By Closing The Browser), But When They Delete Their Cookies, Then That User Has Surpassed My First Law, And Now My DB Incorrectly Assumes That The User Is Still Logged In.