Page 1 of 1

How do you auto-logout someone?

Posted: Tue Aug 14, 2012 3:18 am
by simonmlewis
Hi

I have a simple script that when someone logs in, it stores their cookie, and marks them as 'online'. Then customers who need help from that person can see that at least one person is "online".

The problem I'm facing, is that this person tends to close their browser or their computer without logging off, and thus their status remains' online'.

HOWEVER.... when they go to login next, it won't let them login because their status is already online, the system won't let two people login with the same one set of credentials (security), and since their cookie has timed out, they must login in order to use it.

So... how do you have a script running in the background somehow, that updates their status in the DB to "offline"?

Simon

Re: How do you auto-logout someone?

Posted: Tue Aug 14, 2012 5:59 am
by Grizzzzzzzzzz
a quick example, you could have a polling event occurring in the background, updating a timestamp field every 10seconds. If there hasn't been an update in the past 15seconds, treat that user as offline, if there has been, they're online. That way if there's a powercut, someone closes a browser or turns of their computer without logging out, the polling event no longer happens, so the timestamp field associated with that user doesn't get updated, so they are then treated as offline.

Re: How do you auto-logout someone?

Posted: Tue Aug 14, 2012 11:05 am
by requinix
Do they have to remain logged in as long as the browser window stays open?

Re: How do you auto-logout someone?

Posted: Tue Aug 14, 2012 4:01 pm
by simonmlewis
Yes, because they will click away from a screen to view another, like list of conversations or something else. I did try a closing window script but caused a lot of harm.

Re: How do you auto-logout someone?

Posted: Wed Aug 15, 2012 3:42 am
by simonmlewis
To Grizzzzzzzzzz
I don't know how to do that polling thing.
I know how to run PHP actions on command, but not things in the background. This could be very useful to know, as it would help to monitor web sites to ensure they are active as well.

Re: How do you auto-logout someone?

Posted: Wed Aug 15, 2012 10:36 am
by Grizzzzzzzzzz
simonmlewis wrote:To Grizzzzzzzzzz
I don't know how to do that polling thing.
I know how to run PHP actions on command, but not things in the background. This could be very useful to know, as it would help to monitor web sites to ensure they are active as well.
Keep in mind that this is only really a light weight solution as well, but relatively easy to do using Javascript / JQuery (assuming you've used them before)

http://api.jquery.com/jQuery.post/, that will come in handy

anyway roughly what you need:

- JS that polls a PHP file every X amount of seconds
- PHP file that handles polling & updating timestamps (you'll need an ID here to identify people, IP? Session Token? Security is something to consider)

If you really don't have a clue about polling, here's a very quick example I cobbled together

Code: Select all

<?php

if (isset($_POST['uid']))
{
  echo "you were online at " . date('H:i:s');
  exit;  
}

?>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
  
  sendPoll();
  
  function sendPoll()
  {
    $.post( "poll.php", { uid: "uid" },
      function( data ) {
          $("#result").append("<p>" + data + "</p>");
          setTimeout(sendPoll, 5000);
      }
    );
  }
  
});

</script>

<div id="result">
</div>

There's alot to consider though.

How many people will be using this system? How accurate does it need to be? Is it for just internal use, or externally?

Like I mentioned, what i've suggested should probably only be used in a small scale situation, if you've got many people using it and it needs to be extremely precise, I wouldn't advise this kind of solution.

Re: How do you auto-logout someone?

Posted: Wed Aug 15, 2012 10:44 am
by simonmlewis
It's for use at the moment by just a handful of people.
But hopefully by many more.
It's a tricky one. I am very tempted to put a script into a web site that uses this script, and if the time is after say 8pm, then run a script that marks the person "offline", but that too wouldn't fix theproblem if it is used on more sites.