Chat Room | chat room
After a period of ASP learning, the following we combine the content learned to build a simple chat room, although very simple, but we can through him to master a chat room to establish the basic process, and can constantly improve its function.
The following are the main steps:
1, add the code inside the Global.asa file. This section of code deals with the Application_OnStart event, in which a 15-element data is defined, and assigns it to a Application object's properties. The contents of the Global.asa file are as follows.
2, add the code to the aspchat.asp file. Note that this part of the code is added between the two horizontal lines in the home page, which is between two
<p align= "center" ><font size=5> a simple chat room </font> </p>
<br>
<%
Processing input
If Request.ServerVariables ("request_method") = "POST" Then
Mark the Speaker
If Len (Request ("txtwho")) >0 Then
Session ("Sswho") =request ("txtwho")
End If
Block application objects
Application.Lock
Create a local reference pointer
Mlcounter=application ("Gicounter")
Machats=application ("Gachats")
If the number of rows written is more than 10, restart the count.
If Mlcoundter>9 Then
Mlcoundter=0
End If
Increase user input, counter plus 1
Machat (Mlchounter) =session ("sswho") & ":" &request ("txtcents")
Mlcounter=mlcounter+1
Set the local variable to be valid within the scope of the application.
Applicati "Gicounter") =mlcounter
Application ("Gachats") =machat
Eliminate blocking of application objects
Application.UnLock
End If
%>
<%
Write to TextArea
If Application ("Gicounter") =0 Then
Lstemp=application ("Gachats") (0)
Else
For x=0 to Application ("Gicounter")-1
lstemp=lstemp& "<br>" Application ("Gachats") (x)
Next
End If
Response.white lstemp
%>
3, and finally the content of the txtwho initialization. That is, when the viewer enters his or her own name once, the user does not have to enter it again, in order to distinguish each of the different browsers, where the "session" object is used. Using session ("sswho") Record the name of the visitor. The following code is written directly below the above code into the aspchat.asp.
<form method= "POST" action= "aspchat.asp" name= "frmasp"
<div align= "center" > <center> <p> Spoke: <input type= "text" name= "txtcents" size= ""
</center> </div> <div align= "center" > <center> <p> Object: <input type= "Submit" value= "send" Name= "B1" > </p>
</center> </div>
</form>
4. Complete. Just put the 2, 3 step code before and after adding the complete HTM file code and then save as aspchat.asp on it, this is a very simple ASP chat room program, we can continue to strengthen its function as the study of the depth!