I would like to know how am i able to design a system in such a way that the system knows which user is logon to the system ?? How does the structure of the mysql database ? is there a table to keep track of all the user who is login to the system ?? When a user login to the system, does the username get inserted in a table ?? If this is the case, than when a user close a browser, how the system knows how to remove the name from the table ??
is there any tutorial that i can find further information on this ??
Who is online ??
Moderator: General Moderators
On each page view
Delete from `online` WHERE `user` = '$user'
insert into `online` the $user and the current timestamp
Then to figure out whos online
$time = (time()+120);
SELECT distinct(`user`) FROM `online` WHERE `timestamp` > $time;
Basically we are pulling out where the user has made a page view in the last 120 seconds (2 minutes)...... You could use javascript to detect a browser close but no one really bothers doing that, usually 2 minutes of inactivity means they have left.
You can also make a Logout set them as inactive that way if a user logs out they do not see themselves in the online users list
Delete from `online` WHERE `user` = '$user'
insert into `online` the $user and the current timestamp
Then to figure out whos online
$time = (time()+120);
SELECT distinct(`user`) FROM `online` WHERE `timestamp` > $time;
Basically we are pulling out where the user has made a page view in the last 120 seconds (2 minutes)...... You could use javascript to detect a browser close but no one really bothers doing that, usually 2 minutes of inactivity means they have left.
You can also make a Logout set them as inactive that way if a user logs out they do not see themselves in the online users list
Yes it goes on every page,
the way I do it is usually:
On every page do:
Then on "timed_actions.php" put your code to delete from `online` and then `insert` into online.
To use javascript you could make an onunload="function()" in your body tag, then define the function in the head tag, make it put a popup window and make that popup window set them as inactive then close... problem is most people have popup blockers so I would just go with the timed method
the way I do it is usually:
On every page do:
Code: Select all
<?php
include("timed_actions.php");
?>To use javascript you could make an onunload="function()" in your body tag, then define the function in the head tag, make it put a popup window and make that popup window set them as inactive then close... problem is most people have popup blockers so I would just go with the timed method