View Full Version : counter
canudo
03-31-2003, 06:39 PM
I'm, sorry but i cannot show you gus the code because had the stupid idea of erasing it..
I had it online were i was testing it but i deleted it..
Has far as the code goes i'm pretty sure it was correct..
Can anyone give an example of how to create on in Javascript or ASP, in a symplified way...
i know it sounds a bit stupid but i don't reallly like using hit counters and never had much interest on using them. For the first time someone ask's one from me and i just can't do it :confused:
Sorry 'bout this and thanks to you all.
CaNuDo:D
Morgoth
03-31-2003, 08:36 PM
So, you want a hit counter in ASP?
Well, there are many types!
One I suggest (very easy) is one using a text file database, and no ip clocker...
So everytime the page is refreshed it will add one to the text file..
Simple code for this can be found online...
For Great, Free, Scripts, Tutorials, Sites:
http://www.aspin.com
But here's a simple hit counter.
<%Option Explicit%>
<%
Dim FSO, CounterFile, Hits, OpenFile, CreatFile
Set FSO = CreateObject("Scripting.FileSystemObject")
CounterFile = Server.MapPath("counter.txt")
On Error Resume Next
Set OpenFile = FSO.OpenTextFile(CounterFile)
Hits = Clng(OpenFile.ReadLine)
Hits = Hits + 1
OpenFile.close
If Error Then
Hits = 1
End If
Set CreatFile = FSO.CreateTextFile(CounterFile,True)
CreatFile.WriteLine(Hits)
CreatFile.Close
%>
Total number of times page has been viewed: <%=Hits%>.
^^Should work...
oracleguy
03-31-2003, 11:24 PM
One simple thing I'd suggest in addition to Morgoth's code is make it set a session variable and once the variable has been set, it doesn't add one to the hit counter.
whammy
04-01-2003, 12:03 AM
Like this one (also I can't see any reason for using On Error Resume Next, since like below you can read from the file if it exists. If not, the file is created anyway with "Set cf = cfs.OpenTextFile(thefile, 2, True)".):
http://www.solidscripts.com/displayscript.asp?sid=4
<%
Dim cfs, cf, thefile, counter, sMapPath
sMapPath = Server.MapPath("\")
thefile = Mid(sMapPath, 1, InStrRev(sMapPath,"\")-1) & "\database\counter.txt"
Set cfs = CreateObject("Scripting.FileSystemObject")
If cfs.FileExists(thefile) Then
Set cf = cfs.OpenTextFile(thefile, 1)
counter = cf.ReadLine
End If
Set cf = cfs.OpenTextFile(thefile, 2, True)
If Session("counted") <> "1" Then counter = counter + 1
cf.WriteLine(counter)
Set cf = Nothing
Set cfs = Nothing
Session("counted") = "1"
%>
You can probably tell from that code where I learned FSO (and some of the nice little tricks, although I still haven't used them all!):
http://www.w3schools.com ;)
Morgoth
04-01-2003, 02:25 AM
That's a great website...
I go their for and CSS code I can't remember..
(I feel I know moe CSS because of the lessions they tell you)
Mhtml
04-01-2003, 07:01 AM
Why did you start a new post?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.