Server Page Code Snippets
Creating a Simple Page Counter *1
This code will create a very simple page counter. It gets
incremented every time the page is loaded and if the server is shutdown
the count is lost.
' Lock the application
' Get the name of the file name executed
sFileName = Request.ServerVariables("SCRIPT_NAME")
' Increment the count for this file
Application(sFileName) = Application(sFileName) + 1
Response.write "<H1>" & Application(sFileName) & "</H1>"
' Unlock the application
Stripping HTML Tags from a String
If you need to prevent html code from be displayed(e.g.
A Message board were added HTML could stuff up the layout) you can use
this script to remove the html tags from a string.
Function StripHTML(ByVal strHTML)
Total = Len(strHTML)
' Scan if there is a tag, and determine if you should add it
' to the finished file.
For i = 1 To Total
Select Case Mid(strHTML, i, 1)
InsideTag = True
InsideTag = False
' If it is InsideTag then don't add it to the file, and
' if it isn't, then add it to the previous ToFile text.
If Not InsideTag Then StripHTML = StripHTML & Mid(strHTML, i, 1)
*1. This code sample
was printed in "Build Simple Hit Counters in ASP" by Manohar
Kamath, Microsoft Interactive Developer, August 1998, copyright
Microsoft Corp. and is reprinted by permission. All rights reserved. For
more information about MIND, please visit www.microsoft.com/mind.