rat in a cage Posted October 24, 2010 Share Posted October 24, 2010 Hi, im new here Need some help. I have a database which contains users, and for every user i have logged_in value which is 1 if user is logged in and 0 if not. I use this so that user can be logged in only once. When user clicks on logout link i set logged_in on 0. My problem is when browser closes logged_in for current user is not set to 0, and after that user can't login because my site thinks he is already logged in. is there some way I can call some function when browser exits or any other solution? please help Quote Link to comment Share on other sites More sharing options...
ceycey Posted October 24, 2010 Share Posted October 24, 2010 You must use cookies or sessions in such a situation, your method is wrong.. The membership systems are created using session or cookie method: when the user submits the login form, a cookie is sent to user's computer and when the user browses the web page later, the cookie is detected. But still you can use javascript onclose event that is thrown when the user attempts to close web page but it is not a solution. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted October 24, 2010 Share Posted October 24, 2010 His method is not entirely wrong, it prevent multiple people logging into the same account. I use this method currently along with $_SESSION's, I also use a field in the database for the users last action. I then run a cron job every 5 minutes to check if anyone has been idle for longer than 5 minutes, if they have, they are logged out on there next action, this prevents people using there account if they forget to logout. Plus it's the best way to get an acurate reading of people online, and you can set different time frames etc. Hope this helps your situation Regards, Paul. Quote Link to comment Share on other sites More sharing options...
rat in a cage Posted October 25, 2010 Author Share Posted October 25, 2010 You must use cookies or sessions in such a situation, your method is wrong.. just as PaulRyan sad i use this to prevent multiple people log in to same account. i do use session too for username and other stuff. But still you can use javascript onclose event that is thrown when the user attempts to close web page but it is not a solution. yes, i'm aware of this but as you said javascript is not a solution in my situation. I use this method currently along with $_SESSION's, I also use a field in the database for the users last action. I then run a cron job every 5 minutes to check if anyone has been idle for longer than 5 minutes, if they have, they are logged out on there next action, this prevents people using there account if they forget to logout. how to check for users last action? hm, I also don't see solution to my problem i still have to put logged_in flag to zero when browser is exited but i don't wanna do it with javascript. anyway thanks for answers people Quote Link to comment Share on other sites More sharing options...
revraz Posted October 25, 2010 Share Posted October 25, 2010 Can set a last activity time in the database and after say 5 mins have it set them as logged out. Quote Link to comment 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.