I am trying to show in my chat script whether user who sent message is online or offline.
For that, there is continuous 800milisecond ajax going on to fetch chat message from chat.txt file, but my problem is to show whether given user is online or offline status.
I have tried this :-
function show_status() {
var id = ("#id").val();
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("status").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",'/status.php?id='+id,true);
xmlhttp.setRequestHeader("Content-type","text/html");
xmlhttp.send();
}
and in status.php ... i have this code :-
<?php
if(isset($_GET['id'])) {
if( $_GET['id'] === '123') {
echo 'Online';
} else {
echo 'Offline';
}
}
if( $_GET['id'] === '321') {
echo 'Online';
} else {
echo 'Offline';
}
?>
But problem is , If my id is 123 , it shows to me, my account as online and even if 321 is online it shows offline and for user with is 321, it shows his id 321 online and other account offline, is there any method, to overrule.. this and show all current user who are online as online. Without touching database, i don't want to run query every time in database.