The usual chat room using the program, that is, the chat program, the basic structure of the principle will not be used to the database. What kind of technology does it take? We know that the function of the session variable in the ASP variable is to record the information of a single user, and to track the behavior of the user, and the global variable of the function of the Application object, which can be used to share information among multiple users of the site in the page.
It can be imagined that in the current chat program, a chat member is a session variable, chat members of the conversation as a application variable to share the display, so that members can see.
The following is a very classical example of the process of 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= "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")%> speak: <input type= "text" name= "talk" Size= "M" ><br> <input type= "Submit" value= "submitted" > <input type= "reset" value= "Cancel" ></p> </form> <a href= "chat.asp" > Leave </a><br>
<% If Request.Form ("log") <>1 Then If Trim (Request.Form ("talk")) = "" Then Talk=session ("Nick") & "Don't say a word, just want to be perfunctory." Else Talk=trim (Request.Form ("Talk")) End If Application.Lock Application ("show") = "from" &request.servervariables ("REMOTE_ADDR") & "&session" ("Nick") & "in" & time& "Time to say:" &talk& "<br>" &application ("show") Application.UnLock Response.Write Application ("show") End If %> <%end if%>
|
Simple explanation:
The function of the 1,<%if request.servervariables ("request_method") = "Get" then%> is to determine how the current page is accepted and, if it is, to display a form page that requires a nickname to be entered. Because the page silently accepts the way to get, when in the URL address bar knocks directly, namely does not have any information, should display the request "enters the nickname".
2,<input type= "hidden" name= "Log" size= "1" > and the following if value= ("Log") Request.Form Then is associated: it is obvious that the first time a nickname is entered, the Log hidden field is also sent. But as for the first time the entry was without any statement to speak of, so judged accepted by the
log value is not 1, i.e.
non-first sign-on(indicates that you are already logged in), perform an internal related chat display.
3,trim (Request.Form ("talk") = "", Trim is a function: Delete the space before the string. At first this, there are RTrim (): Remove the space after the string; LTrim (): Remove the space before the string.
<textarea class="bk" id="temp97161" rows="12"><script language=vbs> cnbruce= "This is a Test!" Alert (show: &cnbruce) alert (delete front space: <rim (cnbruce)) alert (delete trailing space: &rtrim (cnbruce)) alert (" Delete before and after space: "&trim (cnbruce)) </script></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]
4,
Application.Lock Application ("show") = "from" &request.servervariables ("REMOTE_ADDR") & "&session" ("Nick") & "in" & time& "Time to say:" &talk& "<br>" &application ("show") Application.UnLock
|
Extract the Essence to
Application.Lock Application ("show") =talk& "<br>" &application ("show") Application.UnLock
|
Can see is the application variable superposition function, each application ("show") the value is based on the original application variable value, and then attach the latest chat content: Talk variable value. This will ensure that all users can see the shared information.
Not finished