This article mainly introduces four steps to complete the traffic statistics of Asp web design. Interested friends can refer to it.
Follow the steps below and you will soon have a beautiful graphical counter.
Step 1:
Create a text file in a directory of the website such as count, such as counter.dat, to store visits. The file content has only one line of numbers, indicating the initial visits to the website, which is generally 0.
Step 2:
The ASP program that creates a counter in the same directory can be named mycount.asp, with the following content:
- <%
- 'Manufactured ASP graphical counter V1.1
- 'Used for web browsing statistics, free to use, free to copy!
- dimvistors
- 'Get the address of the count file counter.dat
- countfile=server.mappath(counter.dat)
- 'Create filesystemobject object instance fs
- setfs=server.createobject(scripting.filesystemobject)
- 'Open the file in read mode, where 1 is read mode
- setthisfile=fs.opentextfile(countfile,1,FALSE,FALSE)
- 'Read the contents of the count file
- visitors=thisfile.readline
- 'Close the file
- thisfile.close
- setfs=server.createobject(scripting.filesystemobject)
- 'Create a file in override (TRUE), in ASCII format (FALSE)
- setthisfile=fs.createtextfile(countfile,TRUE,FALSE)
- 'The key points of the counter:
- 'Added variable connected to determine whether the visitor is a new linker
- 'This move prevents the same user from browsing in the same time, due to multiple pressing of the browser's refresh button,
- 'The phenomenon of increasing the counter value occurs
- ifIsEmpty(session(connected))then
- application.lock
- 'Other users are prohibited from changing the counter value
- visitors=visitors+1
- 'The counter value is increased by 1
- thisfile.writeline(visitors)
- 'Write the result to the file
- application.unlock
- 'Cancel lock, allowing the user to change the counter value
- else
- application.lock
- visitors=visitors
- thisfile.writeline(visitors)
- application.unlock
- endif
- session(connected)=TRUE
- 'Set the visitor to be connected (TRUE), and press the refresh button again to the counter value will not change.
- countlen=len(visitors)
- 'Get the length of the counter value (i.e. the number of digits of the value)
- 'If you don't want to use graphics, you can use the following instead of the for/next loop
- 'Text counter: response.writedocument.write(&visitors&);
- 'Display graphical numbers bit by bit
- fori=1tocountlen
- response.writedocument.write('<imgsrc=&images/&/&mid(visitors,i,1)&.gif></img>');
- next
- 'Close the file
- thisfile.close
- setfs=nothing
- %>
Step 3:
Place the counter.dat and mycount.asp files in the same directory (can also be stored separately, but the file path needs to be specified at this time), and create an images directory in this directory to store graphical digital files, requiring the number 0 to correspond to 0 .gif, the number 1 corresponds to 1.gif, and so on (the opportunity to show your personality is here, you can make the number very cool).
Step 4:
At this point, the great achievements are about to be completed. You just need to call the counter in the following format on the web page:
- <scriptlanguage=javascriptsrc=count/mycount.asp>
- </script>
Notice:
(1) If you use different directory names and file names, please make corresponding changes;
(2) The counter program is programmed by ASP. Please test it on the website or debug it on the personal server PWS;
As long as you study the above four steps carefully and carefully, I believe that you will definitely create an Asp web design traffic statistics with your own style characteristics.