Pergunta

I am creating an application where users cannot attempt multiple logins. If a particular user logs in, my database flag value becomes set to 1 that means no other member who has the same username and password can login.

If a user signs out my database flag value is set to 0. That's all working fine but now I have one different problem that is when a user suddenly closes the browser without logout page or session is timeout then automatically the database flag value should be set to 0. Now I don't know how to do it. Please give me any solution.

Foi útil?

Solução

In your Global.asax file you have Session_OnEnd()

public void Session_OnEnd()
{
    // Set flag to 0
}

This will be okay if your sessionState is set to INPROC (Which is the default setting), if you have manually adjsuted it to StateServer or SQL Server then this event will be ignored.

When the browser closes the window you can do use onbeforeunload in JavaScript

window.onbeforeunload = function(e) {
  // call an Ajax function to reset the state.
};

Outras dicas

Simply create a column isloggedin in database

eg:

USERNAME | PASSWORD | isloggedin | logintimestamp

    user | pass     | 0          | 3/9/2013 23:59:59

and set it to 1 when user logs in and while theuser is logged in use ajax to update current time in db...

if this fails to do make timer functions to check the loggedin value depending on timestamp http://dev.mysql.com/doc/refman/5.1/en/events.html

here is the tutorial: http://www.sitepoint.com/how-to-create-mysql-events/

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top