Jump to content

logout problem


rat in a cage

Recommended Posts

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 :confused:

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.  :confused:

 

anyway thanks for answers people  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.