Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
That is: If the user close the browser instead of clicking on Logout button, How can I catch that event. Because if the user login, I will tick the status field of that user in my Database, so that if they close the browser instead of clicking on Logout button, I cant uncheck the status field of that user in my Database.
Can you show me how to solve that problem?
plz give me the detail solution or some code fragment..

I want to track user (ie: login and logout time)
and user login at once (ie: if user login then not allow to login again till it log out)

I am doing this by using data base Is their any other way to do that
please suggest.

Hey Christian Thanks you very much :thumbsup:
and I totlay agree with your answer
but I have little bit confusion Please could you explains me
in brief that would help me more


(^_^)!
Thank you in-advanced!
Posted
Updated 15-Jan-10 0:35am
v6

"Thanks Abhishek.
that means i will set automatic timeout
after sometime..

1 - how do i set logic of automatic timeout in the server"

It would sure help if you'd edit your post instead of posting answers that are really questions.

There is no need to do this until the next time the person logs in. You can get a list of logged in users by applying a timeout in your SQL query for a list. You can give admins the ability to log a user out. You can redirect to the login page if a user tries to access a page, and the DB records that they were logged out. When someone tries to log in, you simply require that the timeout period has passed, then you log them in. If you block someone from logging in, you need to show them what the timeout period is, because you WILL have users who close a browser accidentally, for example, and when they try to log back in, the system will think they are a new user logging in while the old session is still valid.
 
Share this answer
 
Thanks Christian for ur reply
thats i want user not allow to logging in twice
at same time track user login and logout that why
i used database..is their any other option..
 
Share this answer
 
Thanks Abhishek.
that means i will set automatic timeout
after sometime..

1 - how do i set logic of automatic timeout in the server
 
Share this answer
 
wrote:
That is: If the user close the browser instead of clicking on Logout button, How can I catch that event.


You can't, not reliably. The solution is to put a timeout in your database, so every time the user requests a page, it is updated, and if it's more than a certainly amount of time old, the user is logged out. If you accept a login while the user appears to be logged in, is up to you, but if you don't mind the risk of someone logging in twice, or writing the code to kill the old session, that's also not a bad idea.
 
Share this answer
 
As christian suggested, it is true, you cant ensure that the page is actually closed or not in the client site.

You might make a workaround using
window.onbeforeunload = function () {
   //Your stuff
}

or rather going for (IE only)
if(window.event.clientX < 0 && window.event.clientY <0)
{
     //Operation
}


to run your code, but you will not be sure that the code will execute. The user might close the process itself which will close the browser immediately and you cant do anything with that.

So It is always better to have a logic of automatic timeout in the server. Just change the last request time to a field in server and give a timeout seed to automatically clear the session after a certain interval(preferrably the Session timeout value).

:cool:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900