tags:

views:

40

answers:

2

Hello All,

I am developing a system in php which has different types of users like admin, A, B, C.

I need to allow log in just one user from the type at a time. Means 1) if there is already an admin user is logged in, no other admin user can log in. 2) And the logged in credentials cannot be used on other pc at the same time (just like yahoo messenger login system).

I have tried to store session with login logout time in database table when someone login and logout. But it creates problem when someone close the browser without logging out, the logout entry time misses.

+1  A: 

You can always set the session expiration time extremely short (say 60 seconds) and use a Ajax postback on each page timed out at say 25 seconds to keep the session alive. This is how Facebook knows if you are "online" for their facebook IM

Anthony Greco
Thanks Anthony for you suggestion. Right now I am using session timeout of 1800 seconds. I will try to extend session timeout period on access of some page. Again Thanks.
AJCE
glad i could help
Anthony Greco
A: 

1) if there is already an admin user is logged in, no other admin user can log in.

If you want to stop multiple logins from same system then set a session flag like $_SESSION['loggedin']=true; while a successful log in occurs, then before each login attempt, check this flag and only when the flag is falseproceed with the login process.

If you want to stop multiple logins from multiple system then create a temporary table in your database to hold the status of your logged-in users and before any login attempts occur check this table to find any logged in user, if you dont find any user then only proceed, or else prompt the user

2) And the logged in credentials cannot be used on other pc at the same time (just like yahoo messenger login system).

create a temporary table in your database, which will hold the status of your all logged in users, then when a user who is already logged-in, attempts to log in from another place, check the status of that userid in your temporary table, if he is already found logged-in then either prompt him or deny him or log him off from other computer before logging him in again.

Starx
Sessions are user-specific. The variable isn't going to be there for every new user.
DanMan
@DanMan, Which Point are you referring to, if its 2, then I proposed the use of db for that purpose?, if its 1, then I am assuming that the different log in attempt is occurring in the same computer, if this is also happening from different system, then we have to use db again in this case.? I will update my answer, if this is what OP wants
Starx
I was talking about 1), yes, and i've assumed that login attempts can occur from more than one computer.
DanMan
Ok, I have modified my answer... Is it enough to answer his queries, or I need to add some more, pls do tell.
Starx
thanks for your answer. It will be helpful to me to prevent multiple logins.
AJCE