Recommended: Flash combined with Asp to create IP, version, login time, number of visits I don’t know if it’s original, but I did it myself without referring to anything. First, you need 2 asp files, 1 text file, and 1 swf file. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
On the Internet, counters written in ASP are everywhere. I think it doesn’t make much sense to talk about ASP writing counters here. Later I thought about it and it was necessary to talk about it, because this is not just about writing counters, but about introducing ASP knowledge and application skills to everyone.
The original program code is as follows:
$#@60;%countlong=8
'countlong defines the number of bits displayed by the counter
On Error Resume Next
′ Ignore all errors
count=server.mappath("count.txt")
set cou = server.createobject("scripting.filesystemobject")
set out=cou.opentextfile(count,1,false,false)
counter=out.readline
out.close
′The above code is to open the file count.txt and read a line to read the current counter value
if session(″in″)$#@60;$#@62;″in″ then
′ Determine whether the user has entered the home page to ensure that the counter will not be added by 1 when he presses refresh or comes to this page again.
session(″in″)=″in″
set out = cou.createtextfile(count,true,false)
application.lock
counter=counter+1
'Counter is increased by 1
out.writeline(counter)
application.unlock
out.close
′The above code is to create a new file count.txt and write a line, and write the value of the counter after adding 1.
end if
co=cstr(counter)
'cstr function is used to convert numeric variables into character
for i = 1 to countlong-len(co)
response.write ″″
next
′The loop statement above is to complete the addition of the 0 picture in front of the counter
'len(co) function gets the length of the variable co, countlong-len(co) gets the number of the previous 0 pictures
for i= 1 to len(co)
response.write ″″
next
The 'mid(co,i,1) function is used to read a character %$#@62 from the i-th bit of the variable co;
The more successful counter is to use session to prevent the user from refreshing the counter multiple times; use text files to record the counter value. Although the code is written longer, it is much better than using the application object, because when the server reboots or changes global.asa, the value of the application object will be cleared; and also use pictures to replace characters, which looks more beautiful and generous!
You can design the counter image yourself, use the file name 0.gif, 1 uses 1.gif, and so on.
Share: 20 Very Useful Tips in ASP 1. How to use Asp to determine the virtual physical path of your website Answer: Use the Mappath method p align=center font size=4 face=Arial b The Physical path to this virtual website is: /b /font font color=#FF0000 size=6 face=Arial %= Server.MapPath(/)% /font /p 2. How do I know the user