Allow only one user login

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
redptam
Forum Newbie
Posts: 8
Joined: Thu Oct 17, 2002 3:25 pm
Location: Atlanta, GA

Allow only one user login

Post by redptam »

Hello,

I am trying to figure out how to allow only one user at a time to login to say a database. I want to prevent update issues such as user 2 overwriting user 1's data. I want to do this with sessions can anyone help?

-Philippe-
User avatar
mr_griff
Forum Commoner
Posts: 64
Joined: Tue Sep 17, 2002 11:11 am
Location: Bozeman, Montana

Post by mr_griff »

There are several ways to implement as setup like this. One way would be to have a database table that you can use as a flag, marking that someone is logged in already. You will probably want to have a field that you can update with the last time the logged in user made a change or visited a page. That way if the user forgets to log out, you do have to manually go into the database and reset the flag so someone else can login. For example if it has been 20 minutes since the logged in user has accessed a page log them out and reset the flag.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

and if you want to do it at the database layer tkae a look at http://www.mysql.com/...MySQL_Optimisation.html#Locking_Issues
redptam
Forum Newbie
Posts: 8
Joined: Thu Oct 17, 2002 3:25 pm
Location: Atlanta, GA

Post by redptam »

Thank you both for replying to my post.

I had thought of using a flag in the database with a timestamp of user's
last page access. However, I was concerned with the logout problem of when the user closes the browser window instead of clicking logout. I was hoping much of this problem would be handled by session expire times.
I must say that I had not thought of table locking at all. However, since I am new to PHP and currently learning about databases in my Database Systems class, I think that table locking is a bit beyond my skillset. I do much appreciate your suggestions though and I may try this in the future!
Is there no way to set a session flag variable that can be seen by all browsers and different users on different computers to check if a user is currently into the database?
Post Reply