Exclusive analytic chat room production Tutorial One

Source: Internet
Author: User

A master of program design, in each development of a project, often through a very strict planning, very strict verification, otherwise, the painstaking development of the program once in the middle to find the problem, it is often naught, from the beginning. In particular, the development of a large project, the planning and verification process is more important than the process of writing procedures.

However, if we are a beginner in programming, we would like to develop a routine that is often the opposite of what we have done. Often starting from the simplest example, to achieve the most preliminary function, and then on a simple basis of continuous improvement of the program, perfect, so that its function continues to increase, development, strong.

I myself have a habit: in designing some small and medium-sized programs, I like to spend more effort to explore, to discover its difficult part, to tap its core, and then start from its core experimental programming. Usually a program has several difficult and core parts. Once these core parts have been tested, we can plan the whole program with confidence, so that the design can be completed more quickly.

We are going to build a chat room, first of all, the overall profile of this chat room should have a preliminary image in our mind, in the numerous public chat rooms, its core is nothing more than:
1, the chat person writes the statement to the text or the database;
2, the browser constantly on the text or database to refresh, read;
3, real-time update on-line customers;
4, the administrator to the chat to kick or IP forbidden operation.

If a novice programmer, you can write database, automatic refresh, acquisition of customer IP experiments, then, in fact, the construction of the chat room is completed more than half. First of all, to complete these experiments, we should at least be familiar with some ASP scripts and some SQL commands.

1, <%ip=request ("REMOTE_ADDR")%>
Your IP address is:
<%=IP%>

This is a script to get the client IP, if you have seen the ASP tutorial, you should know that REMOTE_ADDR is
A server environment variable that returns the IP address of the remote host (client) that made the request.

2, <%
Set conn=server.createobject ("ADODB. Connection ")
Connstr= "dbq=" +server.mappath ("Chat.mdb") + ";D river={microsoft Access DRIVER (*.mdb)};"

Conn.Open ConnStr
Sql= "SELECT * from online user table WHERE name = '" & Request ("name") & "'"
Set Rs=conn. Execute (SQL)

If Rs.bof OR Rs.eof Then
SZ = "'" & Request ("name") &_
"', '" & Request ("D4") &_
"', '" & Time1 & "'"
into_db = "INSERT into online user table (name, gender, login time) VALUES (" &_
SZ & ")"
Conn. Execute (into_db)
End If
%>

This is a very common script for database operations, which contains conditional queries and records additions to the database. Above this procedure we are divided into three parts, such as the above with a space-delimited three parts.
To use the object provided by the component, create an instance of the object and assign the new instance the variable name. An instance of an object can be created using the ASP's Server.CreateObject method, which can be named for an object instance using a variable assignment instruction in the scripting language, as in the following example:
Set conn=server.createobject ("ADODB. Connection ")
The variable conn Here is an object instance created by the ASP program to access the database.
We want to access the database, we must first know where the database is, what the driver of this database, to specify the two points there are two ways: the first is to manually create a server-side database source name, specify the database path, specify the database driver, this method is through the server-side Control Panel in the ODBC To set the. Her advantage is that the database can be limited access rights, increase the security of the database, the disadvantage is that the database is not easy to transplant.
Another way is to use ASP to specify the database path and database driver. You do not have to create a database source manually. In this case, we are using the second method. Server.MapPath ("Chat.mdb") specifies the database path, Driver={microsoft access DRIVER (*.mdb)}; Specifies the database driver, in this case we are using the MS Access database.

Select is a SQL query command. Sql= "SELECT * from online user table WHERE name = '" & Request ("name") & "'" indicates that all names in the online user table in the query database Chat.mdb are equal to the Request ("name"), Requ EST ("name") reads the data named name in the form.

Bof is the beginning of the file and EOF is the end of the file. If rs.bof OR rs.eof then ... Statements are often used to determine if a record exists in the database that matches a condition, and if the record is true, the record does not exist if it is false.
Insert into is an insertion command in SQL that is often used to insert a record.

Above this program, the whole meaning is: Query database online User table for the existence of user request ("name"), if not present this user to add this user to the online user table.

3, <meta http-equiv= "Refresh" content= "4" >
This is the simplest page auto-refresh script, which is an HTML script, not an ASP script. It's simple, it means refreshing every 4 seconds, but in the process of using it, you'll find that there are a lot of problems appearing.

Exclusive analytic chat room production Tutorial One

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.