Introduction to ASP Programming (11): Chat Chat Program

Source: Internet
Author: User
Tags log rtrim servervariables variable trim
Programming | Procedures used in the chat room, 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 an ASP variable is to record the information of a single user and to track the user's behavior.
Application The role of the object is the global variable, you can implement the site to share information between multiple users 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> & Lt;input type= "hidden" name= "Log" size= "1" > Value= Else </form><%response.end Dim response.clear 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=" ><br> < Input type= "Submit" value= "Submission" > <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") & "If you don't say a word, you 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&" said: "&talk&" <br> "&application (" show ") Application.UnLock Response.Write Application ("show") 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 the first entry is without any statements to speak of, so the judge accepted the log value is not 1, that is, not the first login (indicating already logged in) when the internal related chat display program.

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.


<script language=vbs>cnbruce= "This is a Test!" Alert (show: &cnbruce) alert (delete front space: <rim (cnbruce)) alert (delete trailing space: &rtrim (cnbruce)) alert ("Remove space before:" &trim (cnbruce)) </script>

Application.Lock application ("show") = "from" &request.servervariables ("REMOTE_ADDR") & "_" &session ("Nick "&" in "&time&" said: "&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.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.