Hi, a great inspiration for you, might be looking at a simple "users online", session based php/mysql script.
If your users are registerred, you can use session to validate them on client->server and you can update a field in mysql.
PSUEDOCODE for what I'm thinking:
Code:
// always start the session at the very topmost of the pages which you want to use the session variables
session_start();
refreshUserStatus(session_id());
function refreshUserStatus($sid) {
// code here for insert or update user status
}
Yes, I know.. I dont have your code there, since you will have to make it yoru self.
If you wish to sessioncontrol anonymous users, it's no biggie, that just means you can INSERT it into the table you make in mysql.
I would have two fields then:
SID (varchar I guess(255 length?))
timestamp (this updates on insert or update)
When the updateUserStatus runs, you either check for that SID in the DB and update it, or you just insert a new row.
If you insert and insert, you will have more rows in the db. However, you can make a janitor script which purges old rows, eg. like.. drop the rows where timestamp is a day old or so.
Another way to go, if you have a users db, is:
You can have the last_online as a timestamp field in the table, or another table.. It all depends on how you wish to do it.. You can of course also store all info, if you wish.. eg tie. the session id, logged in times, etc. to the user.. In such case, it's also quite easy:
[tbl_user]
user_id (unique id, integer and increase+1)
user_name (varchar 255)
user_pass (remember to crypt the pass with salt)
[tbl_session]
session_id_key (unique id, integer and increase+1)
session_user_id_fk_id (integer, foreign key for tbl_user)
session_id (varchar(255))
session_last_active (timestamp)
You might want to use other fieldtypes, it all depends on how much data you wish to store.. if you wish to have detailed loggingabilities, you store a lot.. if not, you can even just skip storing the session id and you can then just use a timestamp field in the user table, as when the user has authed (logged in), you know he/she most likely is that person and you can say that if that time is less than 5 minutes ago, you can call him/her as an onlien user.
Hope some of my scribble made sence.
Olav Alexander Mjelde