0
I’m making a chat system for a panel, and I already have it ready practically, everything connected to the database, when it login changes to online and when it comes out(click the button) it changes to offline in db.
The problem is, when the user closes the page, I need the bank to be changed to offline, I tried to use the onbeforeunload
as I saw in a forum to do the update as ta the code below, I tried to use the same to make the change when it opens the page again, but is not effecting, I think by a code hierarchy.
I don’t really understand the JS/Jquery and AJAX very well, so I’m a little lost in this question.
window.onbeforeunload = function () {
atualiza_fecho();
};
function atualiza_fecho(){
$.get('assets/inc/offline.php', function(resultado){})
}
Code from offline.php
<?php
session_start();
$session_id = $_SESSION['uid'];
$mysqli = mysqli_connect('localhost', 'root', '');
mysqli_select_db($mysqli, 'cbr_chat');
$q=mysqli_query($mysqli, "UPDATE users SET status = 'offline' WHERE uid = '$session_id'");
?>
The idea is, I closed the page, it doesn’t end my session and only changes the status in the bank to offline, and when I open the page again, it changes to online, all this, without finishing the session or having to log in again.
Hello Paul, so at the moment I am with a certain deadline and not giving me much time to study new systems and implementation of the same in the codes. I don’t want to be ignorant or anything, I appreciate the help, but time is what screws me up.
– Thomas Franklin
You can adopt the same strategy for SQL then. Add a field like
last_activity
which will store a timestamp. This way it is possible to create some ajax connections to update the timestamp and can also be searched online users through a query that takes all records with the Tamp team greater than 10 minutes and display them as "online" for example.– Paulo Martins
I will try this way. Thank you beast ;D
– Thomas Franklin
Have you made any progress? @Thomasfranklin
– Paulo Martins