0

When a user login ,

update play set login='1';

when logout ,

update play set login='0';

but when the user close the browser/tab without using 'logout' , How I can change the value login to '0'.

I m using this 'login' as a flag so that no 2 members cannot login with the same username. (user names are created by the admin and distributed to the students.Password is not used.)

If a particular user logged in then first check his 'login'. if login = 0 then that user 'login' will be updated as 1. else echo already logged in.

Is there any other way to implement this.

2 Answers2

1

The easy solution is to poll the server using AJAX to keep the user logged in (unless they click logout). Change all rows to login='0' unless they are detected as online via an updated timestamp when you do the heartbeat/poll.

For example:

function heartbeat(){
   setTimeout(function(){
      $.ajax({ url: "http://example.com/api/heartbeat", cache: false,
      success: function(data){
        //Next beat
        heartbeat();
      }, dataType: "json"});
  }, 10000);//10secs
}

$(document).ready(function(){
    heartbeat();
});

More info can be found here (from a previous question)

Community
  • 1
  • 1
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
0

It a pretty complex matter and there are a number of solutions in this matter

As @Loz Cherone stated and can be found here you can count your users who have their broswer's page open with some ways

Also here is a discussion of this matter that you should read conversation

I think you should read them and think more what you want exactly to do so you can update your question and get some better answers :)

Community
  • 1
  • 1
Savior
  • 54
  • 9