3
REPLY
Below is the answer for those who have been going through something similar. I first created an extra field in my table called Tempoative where I store the team() as soon as the user logs in. See below:
$tempoAtivo = time() + 30;
After stored, I created a new file called online that works as follows:
<script>
setInterval(function(){
$("#verOnline").load(location.href+" #verOnline");
}, 2000);
</script>
<div id="verOnline">
<?php
$tempoAtual = time();
$tempoAtivo = time() + 30;
$alterar = mysqli_query($conexao,"UPDATE proj_acessos SET Tempo = '".$tempoAtivo."' WHERE IdUsuarios = ".$_SESSION['IdUsuarios']."");
$alterar = mysqli_query($conexao,"UPDATE proj_acessos SET StatusOnline = 'N' WHERE Tempo < ".$tempoAtual."");
?>
</div>
The above code updates the database every 2 minutes with active user time. If the user leaves the system directly through the browser, the time stops updating in the database and when the current time is longer than the time in the database, the status changes to offline.
The question has been edited and is now completely different from the original, and the answers now seem to have nothing to do with the question. if the question has changed, another is created. if it has not changed, more information is added to the original. so it does not seem right to me.
– Miguel Mesquita Alfaiate
Joseph, please avoid editing your question so drastically, otherwise the existing answers are invalidated. Also don’t add an answer to the question itself. Finding the solution on your own is excellent, congratulations! But then you can answer your next question using the form below this page. I reversed your edit and added the original question with the answer. I suggest you put the second part as a new answer, then edit the question and remove that section from there. You can also mark your own answer as right if you feel you should do it. Hug!
– utluiz
the logic is simple and the implementation can take many forms. One way is by using Node.js. Several examples are found on the web.. https://simplapi.wordpress.com/2012/07/02/node-js-websocket-near-real-offlineonline-check/
– Daniel Omine