PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am at present writing a portal site and would like to be able to show users who are currently online (similar to the Users browsing this forum which you can see on this page)
Is this done using a database or application cookies (are they called application cookies in php?)
I have really no idea where to start here and would appreciate if someone can point me to some example code or further reading.
when a user accesses the page check if theyre session is in the table.
If it isnt then add them.
update the table setting the touch field to the current time ( as returned by php's time() command);
to get all the users online ( if you look at this site then u'll see that the amount of users is based on a period of 5 mins ) select all the rows from that table where touch>( time()-(5*60)) ie. all the records that have been touched in the last five mins.
at some point you'll want to delete the old records that are in the table. you can do this from either the function to get the users online or whenever a user accesses the site, or you could even do this from some sort of cron job. either way:
delete from table where touch<( time()-(5*60))
you can either store the username in the table as well to get a list of users.