ngreenwood6 Posted September 12, 2008 Share Posted September 12, 2008 I have created a login for my website. It is working without a problem. When a user logs there username gets put into a session and they can view all the pages that they cannot when they arent logged in. However, I do not want users logging in twice with the same username. I have been trying to think of how I want to accomplish this but would like to know what your suggestions are. Please let me know how you would do it with maybe an example or tutorial. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/ Share on other sites More sharing options...
Derleek Posted September 12, 2008 Share Posted September 12, 2008 seems like you could just create a $logged variable or something that is toggled when the user logs in/out. Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-639898 Share on other sites More sharing options...
Mchl Posted September 12, 2008 Share Posted September 12, 2008 And is shared among all users... This pretty much means storing onformation about logged in users in database I suppose. Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-639904 Share on other sites More sharing options...
revraz Posted September 12, 2008 Share Posted September 12, 2008 If he has a login system, then he probably has a database. Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-639966 Share on other sites More sharing options...
ngreenwood6 Posted September 12, 2008 Author Share Posted September 12, 2008 I do and I have the username stored in the session but how would I use the database for this. The problem that I see is that when a user just closes the page it doesnt log them out hence not updating the database. Any suggestions? This is why I am so stumped! I know that there are websites out there that do this though. Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-639969 Share on other sites More sharing options...
revraz Posted September 12, 2008 Share Posted September 12, 2008 It won't be dynamic like that. You'll have to query their activity and say in 5 mins of no activity, they are considered logged out. Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-639973 Share on other sites More sharing options...
The Little Guy Posted September 12, 2008 Share Posted September 12, 2008 Create a column... "logged" set it to either 0 or 1, and make a "lastAction" column that is updated every time a page loads, this will hold the time of the user's last action. 0 = logged out 1 = logged in When a user logs in, check to make sure "logged" is not set to 1. When a user logs out, change the 1 to a 0. Now what if someone doesn't log out, and just closes the browser? Make a cron job that runs every 1-5 minutes, it will check the "lastAction" column, and set all "logged" columns to 0 where the "lastAction" is greater than 5 minutes, or how ever long you want. You will need to log a user out, if they have been idle for more than 5 minutes and come back, and are logged on somewhere else. Hope this gets you started. Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-639985 Share on other sites More sharing options...
revraz Posted September 12, 2008 Share Posted September 12, 2008 Don't even need a cron job, can check it during login. Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-639995 Share on other sites More sharing options...
The Little Guy Posted September 12, 2008 Share Posted September 12, 2008 Don't even need a cron job, can check it during login. Your right, you could do that too. Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-640016 Share on other sites More sharing options...
ngreenwood6 Posted September 12, 2008 Author Share Posted September 12, 2008 Ok thanks for the help guys I get what you are saying and I think I know what I am going to do. However, I want to set it so that when the visit the next page it sets the current time in the database. How could I easily implement that into each page so that I do not have to add that code to every page that they will be logged into? The main thing that I dont know how to do is: make a "lastAction" column that is updated every time a page loads Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-640066 Share on other sites More sharing options...
Stryves Posted September 12, 2008 Share Posted September 12, 2008 just add include "log.php"; That does the login check on each page Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-640074 Share on other sites More sharing options...
ngreenwood6 Posted September 12, 2008 Author Share Posted September 12, 2008 What would log.php consist of though? Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-640104 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 Why do you not want people logging in at the same time? What if they log in, close their browser by accident, and try to log in during those 5 minutes? They'll be pretty annoyed. Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-640108 Share on other sites More sharing options...
ngreenwood6 Posted September 13, 2008 Author Share Posted September 13, 2008 I have a game on my website that if they were logged in twice they could be doing alot better than if they were only logged in once. I do not want others to feel cheated and I do not want anyone cheating the system Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-640578 Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 They could just open multiple tabs. Quote Link to comment https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-640579 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.