ASP 101 - Active Server Pages 101 - Web04
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash




Script Output:
70066
Increment Count     Toggle Images

ASP HTML Download            FAQ

ASP.NET Version

I wrote this sample to answer the question that I'm sure has been on everyone's mind: "How long can an ASP reference site go before putting up a sample hit counter script?" Well whatever the old record was I think we probably shattered it! I've finally broken down and decided to write one. It's pretty simplistic and doesn't really show off the power of ASP, but what do you want... after all it is just a counter!

It stores it's value in a textfile and counts each request. I didn't bother with a session count. If you're interested in that see my article "Counting Active Users!" and just remove the line that decrements the count!

What I did do is take into account some of the things that you might want in a hit counter. First of all you can use this script two different ways. You can cut and paste it into the page you want the count to appear on or you can use it as an include file and just place one line of text in the document where you want the count to appear. The text should look something like this:

<!-- #INCLUDE FILE="counter.asp" -->

One thing to note about using this syntax is that the count file it creates will be wherever the file doing the including is located and this is not necessarily where the script is located! This may be confusing at first, but it allows you to include the same file and run multiple independent counters on different pages with only one set of the code!

Another thing to note is that it'll create it's own file to keep track of the count if it doesn't find one. This makes it pretty darn easy to install. The main problem you might run into is if NTFS permissions don't allow the anonymous internet user to write to the counter.txt file. Once you get any NTFS issues straightened out all should be right with the world!

The last thing that bears mentioning is that, as it stands, the script will let you choose either plain text or a set of images. You can toggle this by setting the images querystring parameter to true or false. If you always use one or the other it probably makes sense to hard code the value in, but for illustration and flexability I let you change it on the fly. And for those of you who actually care (and are still reading this) the default is to use text.


Samples

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers