Learn how to make a hit counter in ASP.A hit counter is an essential part of a site to know how many peopleare coming to site. Here is an easy way to make a counter. All you needis access to ASP and be able to give a write access to a directory.We're going to save the amount of hits in a .txt file so that we won'tneed to worry about database connections.
Here is what we have to write in English:
- Call the FSO (File System Object) to open it for reading. If count.txt does not exist, the FSO will create it.
- Use the On Error Resume Next function to disregard an error should ASP recieve one in the case that count.txt is empty.
- Read the file to a variable.
- Add one to the variable.
- Close the file, then Open it for writing.
- Write the file in Overwrite mode ("2").
- Close the file.
- Display the number of hits.
- Clear all instances of FSO
<%Set FSO = Server.CreateObject("Scripting.FileSystemObject")Readfile = Server.MapPath ("count.txt")Set File = FSO.OpenTextFile (Readfile, 1,true)On Error Resume NextRead = File.ReadallCount = ReadCount = Count + 1 'incrementsFile.CloseWritefile = ReadfileSet File = FSO.OpenTextFile (Writefile, 2)File.Write("" & Count & "")File.CloseResponse.write("" & Count & "")Set FSO = Nothing%> |
Related Articles
- Simple Hit CounterUse this simple script for a basic click counter to display the amount of hits to your site.
- Counter in ASPA hit counter is an essential part of a site to know how many people are coming to site. Here is an easy way to make a counter. All you need is access to ASP and be able to give a write access to a directory...
- A Nice Hit CounterI shows
Total Hits Unique Hits Todays Hits Todays Unique Hits - Easy Flat File Hit CounterCreate a very simple hit pageview counter without any database! Use flat file scripting to make an easy counter!
- Hit CounterHit counters are used to track the amount of visitors there have been to a cetain page. I have looked through the internet and I have come up with 2 different ways to produce a hit counter.
- PHP CounterA counter is a simple yet essential script when developing web pages.
First of all, we need a file where to store the data ( a simple text file). This file must be CHMODed to 777 (under Linux)
Lets name this file data.txt. Do not forget to include it into the same directory as the PH... - Outwards Link CounterThis will allow you to create a script that will count the amount of times a certain link has been clicked and display the results on your page.
- What are Usage Statistics?Usage Statistics are very important to have. They give you endless amounts of data that you can use to shape the future of your own Web site. With a few clicks of the mouse, you can find out if your latest idea is working or what you might need to do to get more visitors to your Web site...
- Downloads CMS and Clicks Counter1. There are 3 documents we will be creating: downloads.php, downloaditem.php, additem.php. You will need access to a mySQL Database with phpmyadmin, as well as a host with php installed onto it.
2. First lets set up the table in phpmyadmin. go to your database, and run the following SQL Comman... - Download Counter with Apache and PHPInfo: Collect statistics on the popularity of your downloads with Apaches mod_rewrite and PHP. Some sites present you an URI like Example.com, which is less than perfect. Being a Windows user (well sometimes) I expect that when I add a file to my download manager Ill see the filename in the list.....
