I need very simple Counter Code...in which no database is use..
just some line of codes to count the total visitors and thats all...and need this withour java script bcoz i dont have support on domain.....

Raza.
http://www.razasnet.tk
;)

<% Dim counting
counting = Application("apcounter") + 1 %>
<% Application("apcounter")=counting %>
<%= Application("apcounter") %>

only problem is that when the server or iis is restarted it reverts back to 0.

there are other ways though (write a text file to the server) code rather complicated but the counter is set no reverting. let me know if you want the script.

<% Dim counting
counting = Application("apcounter") + 1 %>
<% Application("apcounter")=counting %>
<%= Application("apcounter") %>

only problem is that when the server or iis is restarted it reverts back to 0.

there are other ways though (write a text file to the server) code rather complicated but the counter is set no reverting. let me know if you want the script.

if im placing my site on dot tk...then ?

where the hek is "Tokelau" to start with?

i did't understand "if im placing my site on dot tk...then ?". (ok just alowed popups your host is dot.tk)

I don't know them! I don't even know where Tokelau IS.

the safer way is to have the page write a text file to the system the only problem with this way is that a folder on your sites root needs to be un-write protected fo the text file to be writen to. I used this way of counting "article" hits on www.zoutnet.co.za before i moved it to a database update (reason for change: TOO MANY TEXT FILES ON THE SERVER).

the comments should be self explanitery if not let me know!

PS the page needs to be ASP VBScript!

<% Dim currfile, folderin %>
<% ' change to this file's name
currfile = "index.asp"
' change to which folder the text file must be writen to. Make sure the folder exists first
folderin = "counter" %>
<% ' the first part checks to see if there is already a text file, if not it creates one and assigns a value of 1 to it, the second part reads the text file and adds 1 to the value then saves the file again %>
<%Dim pathtofolder
pathtofolder = Request.ServerVariables("PATH_TRANSLATED")
%>
<% pathtofolder = left(pathtofolder,len(pathtofolder)-Len(currfile)) %>
<% pathtofolder = pathtofolder&"\"&folderin&"\" %>
<%

Dim together
together = pathtofolder&"counter.txt"
Dim check
Set check = Server.CreateObject("Scripting.FileSystemObject")
%>
<% If check.FileExists(together) = False Then %>
<%
Dim newfilename
Dim newfiletext
newfilename = together
newfiletext = "1"
Dim usxFSO, usxTS
Set usxFSO = Server.CreateObject("Scripting.FileSystemObject")
Set usxTS = usxFSO.CreateTextFile(newfilename)
usxTS.WriteLine(newfiletext)
usxTS.Close
Set usxTS = Nothing
Set usxFSO = Nothing
%>
<% Else %>
<%
Dim fsoObject
Dim tsObject
Dim filObject
Dim lngVisitorNumber
Dim intWriteDigitLoopCount
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")
Set filObject = fsoObject.GetFile(together)
Set tsObject = filObject.OpenAsTextStream
lngVisitorNumber = CLng(tsObject.ReadAll)
lngVisitorNumber = lngVisitorNumber + 1
Set tsObject = fsoObject.CreateTextFile(together)
tsObject.Write CStr(lngVisitorNumber)
Set fsoObject = Nothing
Set tsObject = Nothing
Set filObject = Nothing
%>
<% End If %>


<% ' this part reads and displays the records %>
<%
Dim usxFSOread
Set usxFSOread = Server.CreateObject("Scripting.FileSystemObject")
Dim usxTextStreamread
const fsoForReading = 1
If usxFSOread.FileExists (together) Then
Set usxTextStreamread = usxFSOread.OpenTextFile(together, fsoForReading)
countervalue = usxTextStreamread.ReadAll
Response.write(countervalue)
usxTextStreamread.Close
Set usxTextStreamread = Nothing
Set usxFSOread = Nothing
else
response.write "0"
End If %>

from dor tk i mean,, that if im putting your simle counter code on my website....and its running no from iis....but its hosting by others e.g www.dot.tk then what will happen? any chance here that couter will reset,,?bcoz code is not on my side,,it will be run by that dot.tk website....that was thqe question

i used your code (simple counter 1st one) its running good....but if iam changing date in my calender to wrond date..then my page is not opening (in iis) on which i put that code..
let me know about this if u hav time..Thanks alot for ur help

Raza.
hasnainr1@hotmail.com and yahoo.co.uk

if the HOST's IIS gets re-started the counter will be reset. hosting companies tend to prommise 99% uptime for websites but it is the 1% that could reset the counter. send your hosting compang an email asking them to please un-write protect A folder on your site and use the second example. If the counter is not THAT important use the first - ONLY IF THE SERVER IS STABLE!

there is another way ASP has a built in counter component, I tried, I failed, I swore, I moved on! in you case i think it might work. I can't remember if it also gets reset if IIS is re-started

My advise, - send an email about the write protected it is the safest way, also if your site is moved to another server your counter goes with it!!! The "short" way you start from 1 again!

Hosting companies tend to be rather helpfull in thes isues as long as you pester them AND DON'T TAKE NO FOR AN ANSWER!!!

Good Luck

This article has been dead for over six months. Start a new discussion instead.