Good morning everyone,

I am currently building a website for the company where I work and I am looking to get a hit counter so I can pull some usage statistics. Our site is on the Intranet and not everyone has access to the Internet so I would rather not have to link this to an outside website.

Unfortunately, our company does not support PHP... why? No idea, but most of the counters that I have come across are all PHP supported so I am unable to use them.

All of my pages are html pages but I'm hoping there is some code I might be able to add in to do the work. We do support asp so maybe something along those lines? I would hopefully like to track multiple pages so I can see which ones are most popular. I am also hoping that the script which I will eventually use does not make the user click OK or YES everytime they enter the site to run it. I believe it was a VB script I ran before which did that and added the info to a plain text file. I don't mind having seperate text files for each site either, I can use a DB to later pull that information.

Any help would be greatly appreciated.

Thanks everyone in advance!

rcdeck

JavaScript hit counter.

HEADER SCRIPT

<SCRIPT LANGUAGE="JavaScript">
<!--
 function nameDefined(ckie,nme)
{
   var splitValues
   var i
   for (i=0;i<ckie.length;++i)
   {
      splitValues=ckie[i].split("=")
      if (splitValues[0]==nme) return true
   }
   return false
}

function delBlanks(strng)
{
   var result=""
   var i
   var chrn
   for (i=0;i<strng.length;++i) {
      chrn=strng.charAt(i)
      if (chrn!=" ") result += chrn
   }
   return result
}
function getCookieValue(ckie,nme)
{
   var splitValues
   var i
   for(i=0;i<ckie.length;++i) {
      splitValues=ckie[i].split("=")
      if(splitValues[0]==nme) return splitValues[1]
   }
   return ""
}
function insertCounter() {
 readCookie()
 displayCounter()
}
 function displayCounter() {
 document.write('<H3 ALIGN="CENTER">')
 document.write("You've visited this page ")
 if(counter==1) document.write("the first time.")
 else document.write(counter+" times.")
 document.writeln('</H3>')
 }
function readCookie() {
 var cookie=document.cookie
 counter=0
 var chkdCookie=delBlanks(cookie)  //are on the client computer
 var nvpair=chkdCookie.split(";")
 if(nameDefined(nvpair,"pageCount"))
 counter=parseInt(getCookieValue(nvpair,"pageCount"))
 ++counter
 var futdate = new Date()
 var expdate = futdate.getTime()
 expdate += 3600000 * 24 *30  //expires in 1 hour
 futdate.setTime(expdate)

 var newCookie="pageCount="+counter
 newCookie += "; expires=" + futdate.toGMTString()
 window.document.cookie=newCookie
}
// -->
</SCRIPT>

BODY SCRIPT

<SCRIPT LANGUAGE="JavaScript">
<!--
insertCounter()
// -->
</SCRIPT>

If little change, it will be what you need. Do not overpower, I'll help.

Hmm,

I placed that code on my page, though where I put the body code I have nothing showing up, and when I do load the page, at the bottom I get "Errors on page" message (or something close to that.)

I should have also mentioned, it doesnt need to be displayed on the page, just something I can see from the back end.

Very strange. Ok, I'll make of something else

JavaScript hit counter.

HEADER SCRIPT

<SCRIPT LANGUAGE="JavaScript">

corrected javascript

<script type='text/javascript'>

asp server counter

<%
on error resume next 
' Create server object
set fso = createobject("scripting.filesystemobject")
' Target text file to opened
set act = fso.opentextfile(server.mappath("asp_count.txt"))
' Read the value of the text document
' If the text document does not exist then the on error resume next
' will drop down to the next line
counter = clng(act.readline)
' Add one to the counter
counter = counter + 1
' Close the object
act.close
' Create a new text file on the server
Set act = fso.CreateTextFile(server.mappath("asp_count.txt"), true)
' Write the current counter value to the text document
act.WriteLine(counter)
' Close the object
act.Close
' Write the counter to the browser as text ::response can be quoted out or erased
Response.Write counter
%>

Would i just place that code <% through %> into the head of the page? I tried placing it there and i even created the file asp_count.txt with a 1 in it in the same directory but its not updating it :(

like php
it embeds in a html file
the file is renamed .asp
so the intranet server knows what to do with it
links to the file from outside also have to have href=filename.asp

I would go here http://www.w3schools.com/asp/default.ASP [ check the file extension :) ] for self paced tutorials
and the .asp.net and .asp forum one parent up in web development for help from code gurus

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.