Tham khảo tài liệu 'tạo ứng dụng webchat phần 2', công nghệ thông tin, hệ điều hành phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Chapter 26 WebChat As with the other CGI programs the HTTP header is printed to let the Web server know that we are about to send HTML data to the Web browser. However unlike most other CGI programs Web Chat also prints a special code telling the Web browser not to cache the HTML during an active chat session. During a real-time chat the user may reload the page every minute to look at the latest messages. It would be a waste of disk space to cache data that is constantly out of date. Thus the Pragma nocache message is delivered along with the normal Content-type text html message. The no-cache message is given only if a session form variable is set. This is because we want to cache the initial chat room entrance screen even if we do not cache the individual chat sessions. Because the messages are constantly changing it is inefficient for the Web browser to constantly cache those pages. When the user first starts the script no session variable has yet been set and the script can use this fact to determine its course of action. print Content-type text html n if in session ne print Pragma no-cache n n else print n The form variables are read to regular Perl variables for easier processing later. chat_username is the username of the user who is chatting. chat_email is the E-mail address of the user. chat_http is the URL that the user is associated with. chat_username in chat_username chat_email in chat_email chat_http in chat_http refresh_rate is the number of seconds before the browser automatically reloads the chat script to display the new messages. 696 Chapter 26 WebChat refresh_rate in refresh_rate how_many_old is a user-defined variable that determines how many old messages should be displayed along with the new messages. how_many_old in how_many_old frames is set to on if the user has chosen to use Netscape-style frames for interacting with other users in the chat room. With frames the chat room is divided into two windows one frame for viewing the messages and