Forum Moderators: coopster
On the last page of the tutorial, the author suggests further improving the script by adding another frame with the usernames(nick) currently online. It is also suggested to include a logout button. In addition, I would think you would have to use some kind of timestamp to automatically remove nicks after a given amount of time should the user close the window instead of using the logout button (unless there is another way).
For the life of me I can't figure out how to do this. I have searched and searched the internet for something to point me in the right direction, and I have come up empty. There are numerous tutorials about how to find the total number of online users, but not the specific usernames(nick). I don't quite understand the authors suggestions on how this might be done.
I also don't understand the global $HTTP_SESSION_VARS; portion of the script. What does this do?
Any help will be greatly appreciated!
as the scripts and the database in the tutorials are very simple indeed, there is no way of tracking down the state of an individual chatter, whether he is logged in or out. You will have to add a datetime type column to the messages table, updated with the value "now()" at every message and query on this to see who hasn't contributed to the chat in a reasonable interval, thus assuming this user has finished chatting.
Something like
SELECT theNick FROM chatScript WHERE unix_timestamp() - from_unixtime(msgtime) < 900;will output all users who have contributed to the chat during the past 15 minutes. You will have to tune the interval according to your users' chat habits.
The $_HTTP_SESSION_VARS array is deprecated. Use the $_SESSION superglobal instead. If you are unfamiliar with sessions in PHP, I recommend reading the documentation on this at [php.net ] . Session handling basically assigns a unique key to every web user, stored in a cookie or as a query string automagically string appended to every URL. You can then save data related to this specific user on the server. The data can be assigned and retrieved using the $_SESSION superglobal array. This is a convenient method for designing stateful websites.