Four common instance programs used in ASP Dynamic Web site

Source: Internet
Author: User
Tags array count current time end key readline trim access
Program | dynamic

  One, Enable Web sites and users to interact

You can make a Web page like senduserinfo.htm, just use the <form method= "post" action= "--webbot-self--" > Change to <form method= "post" action = "userinfo.asp" > can transmit the data you submit to userinfo.asp processing.

Userinfo.asp's source code request.form ("UserName"), Request.Form ("Usergender"), Request.Form ("UserInfo"), Usergender and UserInfo are the name representations of the data to be submitted in senduserinfo.htm. You can compare senduserinfo.htm with userinfo.asp. The following is a partial explanation of Userinfo.asp's source code

<% ASP uses the VBScript language, and you can also change to a JavaScript language. %>
<%@ Language=vbscript%>

<% ' userinfo.asp

Option Explicit
Response.expires=0

Dim StrName, Strgender, STRM, STRMSG

' Get senderuserinfo.htm's name: Name= ' UserName ' transmitted data.
StrName = Trim (Request.Form ("UserName")) ' trim function is used in addition to trailing spaces

' Get Sex in senderuserinfo.htm:: Name= ' usergender ' data sent over
Strgender = Trim (Request.Form ("Usergender"))

' Get senderuserinfo.htm message:: Name= "UserInfo" sent over the data
STRM = Trim (Request.Form ("UserInfo"))
STRMSG = Replace (Strm,vbcrlf, "<Br>" & vbCrLf)
%>
<HTML><BODY>

<% ' Displays the obtained data%>

Name: <%= strname%><br><br>
Sex: <%= strgender%><br><br>
Message: <Br><Br>
<%= strm%><br><br>

</BODY></HTML>

  Second, the website counter

function: All IP addresses that have visited this page

Implementation method: The IP address that has visited this webpage is stored in the count.asp, every once in a while, check, login to this site IP address, if not in the count.asp, indicating that this user has not been before, add to count.asp, if already exist, then the user has previously logged Web site that can be ignored.

1: Access to the IP address of this page, stored in the OLDIP array
Countfile=server.mappath ("count.asp")
Set streamf=createobject ("Scripting.FileSystemObject")
Dim Oldip ()

Set Thisfile=streamf.opentextfile (Countfile,1,false)
Do as not Thisfile.atendofstream
Thisline = Thisfile.readline
' Using the Preserve keyword, you can only resize the last dimension of the array, and you cannot change the dimension of the array.
' The array has only one dimension, and the dimension is the last and only one, you can modify the size of the array.
Redim Preserve Oldip (countly)
Oldip (countly) = Thisline
' Countly records the number of thisfile lines
countly = countly + 1
Loop
Thisfile.close

2: Start checking to see if the current visitor joins the current IP address in the count.asp, using the OLDIP array to determine
Flage =1
Arriveip = Request.ServerVariables ("REMOTE_ADDR")
' Response.Write Arriveip
For I = 1 to countly
' Request.ServerVariables (' remote_addr ') gets the IP that emits the requesting machine
if (Arriveip = Oldip (I-1)) Then
Flage=0
End If
Next

3: If the current IP step in the count.asp, add to the count.asp, to determine whether to join the count.asp is based on the flags in 2 to judge
Set Writef = Streamf.opentextfile (countfile, 8, 0)
If Flage=1 Then
countly = countly +1
Writef.writeline Arriveip
End If
Writef.close

4: Displays the IP address of the page visited
<%
Set Thisfile=streamf.opentextfile (Countfile,1,false)
Do as not Thisfile.atendofstream
Thisline = Thisfile.readline
Response.Write THISLINE&AMP;CHR (13)
Loop
Thisfile.close
%>

  Iii. Establishment of the voting system

Function: Vote on the column, choose the column you like.

Implementation method: The results of the vote exist in the Result.txt file, the current working page is voting.asp, the object submitted is voted.asp, when you click the View button, you can view the results of the current ballot. The bug in the middle is that when you submit, you continue to refresh the voted.asp, so that the ballot results are automatically added, think about why? What is the way to solve it? You've met a similar website.

The key to Voting.asp is:
1: Show viewing results
<script language=javascript>
function Windowopen (Loadpos)
{window.open (Loadpos, "Surveywin", "Toolbar,resizable,scrollbars,dependent,

width=400,height=480 ");
}
</SCRIPT>

2: Submit data to voted.asp <form method= "POST" action= "voted.asp" >

3:voted.asp's key is to the following two sentences, the first line is to save the number of software column votes, the second line is to save the number of votes in the computer Studio column. The next procedure is to automatically update the number of votes in the software column or the number of votes in the computer studio column based on the data submitted.
<%
Set files= Server.CreateObject ("Scripting.FileSystemObject")
If Request.Form ("R1") = "Soft" Then
Set filer= Files.opentextfile (Server.MapPath ("Result.txt"), 1, True)
Soft = Filer.readline
Studio = Filer.readline
Filer.close

Soft=int (Soft) +1
Set filer= Files.opentextfile (Server.MapPath ("Result.txt"), 2, True)
Filer.writeline Soft
Filer.writeline Studio
Filer.close
Else
Set filer= Files.opentextfile (Server.MapPath ("Result.txt"), 1, True)
Soft = Filer.readline
Studio = Filer.readline
Filer.close

Studio=int (Studio) +1
Set filer= Files.opentextfile (Server.MapPath ("Result.txt"), 2, True)
Filer.writeline Soft
Filer.writeline Studio
Filer.close
End If
%>

4: The following procedure gets the number of votes in two columns, calculating the percentages and the number of votes.
<%
Set files= Server.CreateObject ("Scripting.FileSystemObject")
Set filer= Files.opentextfile (Server.MapPath ("Result.txt"), 1, True)
Osoft=filer.readline
Ostudio=filer.readline
Filer.close

ncount = Int (osoft) +int (Ostudio)
soft= (M int (osoft))/int (ncount)
studio= (M int (ostudio))/int (ncount)

Soft = FormatNumber (Soft, 2)
Studio = FormatNumber (Studio, 2)
%>

  Iv. Display online IP address

Features: Displays the current number of online Web pages and IP addresses.

Methods: The current Web page online IP address into the people.asp, every one-minute automatic refresh, used to calculate the current page number of online and IP address.

1: The current online IP address and access time into the LY array.
Set Thisfile=streamf.opentextfile (Countfile,1,false)
Countly=0
Do as not Thisfile.atendofstream
Thisline = Thisfile.readline
' Using the Preserve keyword, you can only resize the last dimension of the array, and you cannot change the dimension of the array.
' The array has only one dimension, and the dimension is the last and only one, you can modify the size of the array.
Redim Preserve ly (countly)
Ly (countly) = Thisline
' Countly records the number of thisfile lines
countly = countly + 1
Loop
Thisfile.close

2: Start refreshing access to the current page IP address
Current system time stored in SJ
Sameip=0
For I=1 to (Countly-1)/2
' Get even sequence
' If the online IP address and the current time are more than one minute, then the IP
If DateDiff ("s", Ly (I*2), SJ) >60 Then
Ly (i*2-1) = ""
Ly (i*2) = ""
Countly=countly-2
End If

' Get the IP address just online, if it's still online
' Request.ServerVariables (' remote_addr ') gets the IP that emits the requesting machine
If Request.ServerVariables ("REMOTE_ADDR") =ly (i*2-1) Then
Sameip=1
Ly (i*2) =SJ
End If
Next

3: The latest access to the current page of the IP address deposit people.asp
' Start writing data to people.asp this file
Set Outfile=streamf.createtextfile (Countfile)
For I=0 to Countly-1
If Ly (i) <> "" Then
Outfile.writeline ly (i)
End If
Next

If Sameip=0 Then
Outfile.writeline Request.ServerVariables ("REMOTE_ADDR")
Outfile.writeline SJ
Outfile.close
End If



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.