Why do i only see the status whether online or offline, another can not see it meaning that it can not, but i'm offline for others but for me i'm online ?

$time = time()+300;
$user = $_SESSION['logged'];
$query = mysql_query("UPDATE users SET status='$time' WHERE username='$user'") or die (mysql_error());
$query1 = mysql_query("SELECT * FROM users WHERE status >= '$time'") or die (mysql_error());
$timestamp = mysql_num_rows($query1);
if ($timestamp == 1) { $status = '<span><img src="images/online.gif"></span>'; } else { $status = '<span><img src="images/offline.gif"></span>'; }

Recommended Answers

All 2 Replies

I am afraid this is a more complex issue. If the JavaScript event onunload or onbeforeunload worked than you could call by AJAX a script to let know your database that that user is no more online, but those events don’t really work always and I don’t believe that they ever will through security issues. What I do in most applications I need to know every second who is online is making a javascript function that is executing every x seconds generating an ajax call to the server saying that (I am the x user and I am still online). Of course that is not the best practice for performance.
Throught the last year I experimented with WebSockets and the result was great … but there isn’t yet a good practice for them in all browsers (not even major ones) while Chrome has its own implementation W3C has one other one that none one still fallows (and Firefox says that this is why it hasn’t yet embraced WebSockets)

For now i have not rolled yet to do with ajax, javascript, etc. simple php :), but as i explained my display only logged users can see my status and i want everyone to be able... :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.