Author: cnbruce resending from: 5D multimedia
The common chat room program, that is, the chat program, does not use the basic structure of the database. So what technology is used? We know that session variables in ASP variables are used to record individual user information and track user behavior.
The application object is a global variable that allows multiple users on the site to share information on the page.
As you can imagine, in the current chat program, a chat member is a session variable, and sessions between chat members are shared and displayed as Application variables so that all Members can see them.
Next we will use a classic instance program for understanding and analysis.
1. Chat. asp
<% If request. servervariables ("request_method") = "get" then %>
<Form method = "Post" Action = "chat. asp">
<Input type = "text" name = "Nick" value = "your nick name"> <p>
<Input type = "Submit" value = "come in"> <p>
<Input type = "hidden" name = "log" size = "20" value = "1">
</Form>
<% Response. End
Else
Response. Clear
Dim talk
If request. Form ("Nick") <> "then
Session ("Nick") = request. Form ("Nick ")
End if
%><Form method = "Post" Action = "chat. asp" name = form1>
<% = SESSION ("Nick") %> speaker:
<Input type = "text" name = "talk" size = "50"> <br>
<Input type = "Submit" value = "Submit">
<Input type = "reset" value = "cancel"> </P>
</Form>
<A href = "chat. asp"> exit </a> <br>
<%
If request. Form ("log") <> 1 then
If trim (request. Form ("talk") = "" then
Talk = SESSION ("Nick") & "don't say a word, you just want to give it away"
Else
Talk = trim (request. Form ("talk "))
End if
Application. Lock
Application ("show") = "from" & request. servervariables ("remote_addr _
"& SESSION (" Nick ") &" when "& time &": "& talk &" <br> "& Application (" show ")
Application. Unlock
Response. Write application ("show ")
End if
%>
Simple explanation:
1, <% if request. servervariables ("request_method") = "get" then %> is used to determine how the current page is accepted. If the get method is used, a single table page with "Enter nickname required" is displayed. Because the silent acceptance method of the page is get, when the URL address bar is directly typed, that is, when there is no information, it should be displayed to require "input nickname ".
2, <input type = "hidden" name = "log" size = "20" value = "1"> and the following if request. form ("log") <> 1 then is associated: Apparently, the first time a nickname is entered, the log hidden domain is also sent. However, as the first entry, there is no statement to speak, so the accepted log value is not 1, that is, when the first login (indicating that the user has logged on), the internal chat display program is executed.
3, trim (request. Form ("talk") = "", trim is a function: the space before and after the string is deleted. At the beginning, there is also rtrim (): remove the space after the string; ltrim (): remove the space before the string.
<Script language = vbs>
Cnbruce = "this is a test! "
Alert ("show all:" & cnbruce)
Alert ("Remove leading space:" <rim (cnbruce ))
Alert ("Remove trailing space:" & rtrim (cnbruce ))
Alert ("Remove leading and trailing spaces:" & trim (cnbruce ))
</SCRIPT>
Application. Lock
Application ("show") = "from" & request. servervariables ("remote_addr _
"& SESSION (" Nick ") &" when "& time &": "& talk &" <br> "& Application (" show ")
Application. Unlock
Extracted essence:
Application.lock
Application("show")=talk& "<br>" &Application("show")
Application.UnLock
The overlay function of Application variables is displayed. Each application ("show") value is based on the original application variable value, and the latest chat content is appended: the value of the talk variable. This ensures that all users can see the shared information.