Forum Moderators: coopster

Message Too Old, No Replies

Trying to modify chatroom tutorial

Adding "user's currently online" box

         

oceanwave

12:24 am on Nov 14, 2004 (gmt 0)

10+ Year Member



I successfully uploaded a chat script as per the tutorial [devarticles.com...] (which is a good tutorial if anyone is interested). It works great!

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!

baertyp

8:00 am on Nov 15, 2004 (gmt 0)

10+ Year Member



Oceanwave,

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.

mincklerstraat

12:15 pm on Nov 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wouldn't knock myself out too much trying to add this functionality - in general, php isn't really very good for things which are continuously open and dynamically updated, like chatrooms - most of them use refresh scripts that refresh after x seconds - this can be rather tedious for users, waiting for a refresh before they see updates. In general I'm not a big fan of java applets, but for chatrooms, I definitely think a java applet would be the way to go.

oceanwave

12:57 pm on Nov 16, 2004 (gmt 0)

10+ Year Member



Thanks to both of you for answering.

If I go with a java applet, where do I learn how to program one? I started reading a little, and saw something about "java applet servers". Do I need to be on some special server to run one? I know absolutely nothing about java. Where might I start?

mincklerstraat

1:16 pm on Nov 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd look into just downloading and installing one. J-pilot was, for years, the most common chat applet - it hooks into an irc network; it was commercial and cost about $50. By now you probably have some good free java chat applets out there; google for one or look at hotscripts. Some irc networks will have their own chat applets that you can call up by just adding a page of HTML - these will usually be supported by ads. You could also ask in webmaster general. I'm not up on these any more, I don't have java installed on my linux partition - but probably most users will have it.