Some ASP techniques and practical solutions

Source: Internet
Author: User
Tags date header servervariables table name time interval
Tips | To solve random numbers:
<%randomize%>
<%= (int (rnd () *n) +1)%>
The record keywords that are obtained when querying data are displayed in red:
<% =replace (RS ("field x"), Searchname, "<font color= #FF0000 >" & searchname & "</font>")%>
Using ASP to check whether the visitor used the agent
<% if Request.ServerVariables ("Http_x_forwarded_for") <> "" Then
Response.Write "<font color= #FF0000 > You have passed the proxy server," & _
"True IP is" &request.servervariables ("Http_x_forwarded_for")
End If
%>
Determine the origin of the previous page
Request.ServerVariables ("Http_referer")
JavaScript:document.referrer
Clear Cache, Reload page
<%response.expires = 0
Response.ExpiresAbsolute = Now ()-1
Response.AddHeader "Pragma", "No-cache"
Response.AddHeader "Cache-control", "private"
Response.CacheControl = "No-cache"
%>
Display the year and month in the Drop-down menu
<select name= "Select" >
<%
Dim M_year
Dim M_month
Dim M_MONTHJ
Dim M_themonth
Dim M_ym
For m_year = the Year (Date)
M_month = 12
If m_year = year (Date) Then
M_month = Month (Date)
End If
For M_monthj=1 to M_month
If M_monthj < Then
M_themonth = "0" & M_MONTHJ
Else
M_themonth = M_monthj
End If
M_ym = m_year& "-" & M_themonth%>
<option value= "<%= m_ym%>" ><%= m_ym%></option>
<%
Next
Next%>
</select>
Retrieving and deleting duplicate records in a database
Conn.execute ("Delete from table where ID isn't in" (select distinct from table))

When you are doing an online communication site, there's a problem that's really troubling me about real-time statistics on online users, customer requirements: Statistics of current online numbers, number of visitors, number of members, list of online users, including visitors, members and administrators (if it is a tourist, automatically generate the visitor ID, if it is a member, Displays the name of the member). Because it requires real-time, first I will use the idea of Global.asa solution pass away.
The crux of the problem is how to judge the user has left, and how to execute a file or a function when the user leaves.
After the discussion with some friends on the Internet, we finally solved the problem.
The solution is: write a common page, the so-called Common page, is the application of each page contains this page, such as: header. ASP, on this page, write a piece of code with XMLHTTP, the function of this code is to send a request every 10 seconds or 20 seconds to the server, the purpose is to update the current user's online time and delete online time more than a certain time of users, so that the database of online user records to maintain a certain real-time.
The main implementation methods are:
Create a new database with field name: ID (character), name (character), user (number) TT (date), admin (permission code, 0-Normal user, 1-admin)
Table name: Online
Header.asp↓
============================================================
<%
... ...
If session ("S_in") <>1 and Session ("s_name") = "then" If user is first logged in
Rs.Open "SELECT * from online", conn,3,3
Rs.addnew
RS ("id") =session.sessionid
RS ("name") = "Visitor" & Session.SessionID
RS ("user") =0 ' 0 means that the user is not logged in, is a tourist identity
RS ("tt") =now
Rs.update
Rs.close
Session ("s_in") =1 ' set user's information has been stored in the database, indicating that it has been online
End If
If session ("S_name") <> "then" if the user has logged in through the login box
Rs.Open "SELECT * from online where id= '" & Session.SessionID & "'", conn,3,3
RS ("name") =session ("S_name")
RS ("admin") =session ("S_admin") ' updates the user's name to the member name
RS ("user") =1 ' indicates that the user has landed and is a member
RS ("tt") =now ' sets the current system time to the user's logon time
Rs.update
Rs.close
End If
... ...
%>
... ...
... ...
<script language=javascript>
function Test ()
{
var xmlhttp = new ActiveXObject ("MSXML2. XMLHTTP ");
Xmlhttp.open ("POST", "onceonline.asp", false); Send an update request to onceonline.asp
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send ();
}
SetInterval ("Test ();", 10); 10 seconds to send an update request
</script>
... ...
... ...
==========================================================
Onceonline.asp
<%
Rs.Open "Select TT from online where id= '" & Session.SessionID & "'", conn,3,3
RS ("TT") =now () Update online time for current online users
Rs.update
Rs.close
Rs.Open "Delete from online where DateDiff (' s ', Tt,now ()) >60", conn,3,1 ' Delete timeout user
%>
==============================================================
In this way, the basic guarantee of the real-time user list in the database, the error depends on the update time and the difference between the deletion time and the speed of the server, we recommend that the time interval to remove the timeout user is too small, which may lead to online use



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.