Ready for a Chat ?

Now you can write your own Web Chat program.

For example,
chat

A Web Chat program is really just a guest book that updates.

We will need to redesign the guest book so we can see what we write and what other people have written at the same time.

One way to do this is with a pair of frames.

Chatset.htm - the frameset consists of

<form name='chat' action='cgi-bin/chatin.pl' method='post' target='messages'>

The Submit Comment button runs a perl script, chatin.pl, that adds your comment to a text file and displays a text link that runs chatout.pl

print "<a href='chatout.pl'>Click here to see the updated Chat Line</a>";

Chatout.pl displays the contents of the chattext.txt file.
Make sure you create an empty file called Chattext.txt with appropriate read write permissions.

Chatout.pl also uses the html meta tag to refresh itself every 10 seconds to keep the chat up to date.

print "<meta http-equiv='refresh' content='10; url=chatout.pl' />";

The Reset Form button simply clears the form.

Enhancements
1. See if you can limit the number of entries allowed in the text file to 20 to stop it growing too large.
2. Make sure your chat program strips any html tags from comments before adding them to the text file
(Hint: $value=~ s/<.+?>//g)
3. Rewrite the code so that the latest message is displayed at the top of the Chat.
4. Investigate the flock command to avoid two or more users trying to access Chat at the same time.