I’m working on modifying my users list in one of my applications.
I have an Action column that is used for editing and deleting users. I’ve created a query where if an administrator is logged in, they cannot delete their own account.
However, I need to improve this functionality for other users where administrators cannot delete any user that is currently logged in whether they are an admin or an operator. I’ve read about using session_status() but I’m not sure how that works.
My thinking is I don’t want someone to delete another person’s account while they are logged in using the system because they would get kicked off the system without warning or anything. The admin already can’t delete their own account. In my mind they shouldn’t be able to delete anyone’s account if they are logged into it (unless this really isn’t necessary).
Are you saying that your system somehow warns the user before they show up to their next unscheduled session with your site, at any faster rate than you would do so when the user tries to perform an action and is told their user no longer exists?
What if the user never logs off, or has the same schedule as your admin? Is your administrator just… stuck with a user they can never delete?
So what happens is that when a user logs in, my code checks to see if the user’s account is active and if the password they entered matches the password in the database (which is provided when an account is created by an admin).
When an admin is logged into their own account, they cannot go in a delete their own account (as shown by the grey lock):
However, if the admin needs to delete another user account, they can without hassle:
But what if the user they are trying to delete is logged in to the system and actively working?
Same way as when you logged them in. Check the DB for the active user_id. If it doesn’t exist, force a logout. A function would be appropriate here since you would call it on every page load.