Web Counter program: .... A lot of finger truth.

Source: Internet
Author: User
Web Counter DIY
As the network is on its way, web counters are also popular. In fact, most Web sites have web counters that reflect the amount of traffic on the site. Counter source is very wide, FrontPage and other Web pages editor with a Web page counter, and some sites also provide free counter download. In fact, familiar with the ASP programming, it is easy to make a counter yourself. An implementation method is described below.
The counter principle is: When the first use of the Web page, the initial value of 1, the next time each request page, the counter value plus 1. So we just put a text file on the server counter.txt, the contents of the text file has the value of the counter, each time after each request page, read the number of text file counters, plus 1 display, and then change the original value to add 1 after the value, save to the text file. As for the initial set 1, on the server can not build Counter.txt, in the Web page, first judge whether there are counter.txt files on the server, did not generate Counter.txt, write 1 in the Counter.txt, the page display counter value 1, complete the initial 1. You can set the initial value each time you want to delete the Counter.txt file in the specified directory.
The concrete operation must have the display number 0, 1, the 2....9 image file, 0.gif, 1.gif, 2.gif ... 9.gif, the file can not be too large, general 18*25 can be. You want to put the counter page layout design finished, and then changed to ASP file, the following code input to show the counter where, when used, the program will automatically create a counter.txt file under the virtual directory count. Deletes the file when the initial value is placed. Yes, the virtual directory count must give everyone the Write permission.
<%
Const ForReading = 1, ForWriting = 2, ForAppending =3
Const Tristateusedefault =-2, TristateTrue =-1, tristatefalse = 0
Filepath=server.mappath ("/count")
filename=filepath+ "Counter.txt"
Set Fs=createobject ("Scripting.FileSystemObject")
If fs.fileexists (filename) Then
Set F=fs.getfile (filename)
Set ts = F.openastextstream (ForReading,
Tristateusedefault)
S=ts.readline+1
Ts.close
Else
Fs.createtextfile (filename)
Set F=fs.getfile (filename)
S=1
End If
' Write data to Counter.txt
Set ts = F.openastextstream (ForWriting,
Tristateusedefault)
Ts.writeline (CStr (s))
Ts.close
' Show counters
S=cstr (s+1000000)

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.