Page Counter object and global.asa

Results 1 to 2 of 2

Thread: Page Counter object and global.asa

  1. #1
    Join Date
    Dec 1969

    Default Page Counter object and global.asa

    Hi and thanks<BR>I need a site hit counter, so used Microsofts Page Counter object and put the code in the Session_OnStart function of the global.asa, so that it would increment at the start of every new session. It should increment the counter and store the value in a Session variable, accesible from any other page. But it keeps getting reset. What am I doing wrong?<BR>Here is the code in the global.asa.......<BR>&#060;SCRIPT LANGUAGE=VBScript RUNAT=Server&#062;<BR>Sub Session_OnStart<BR> Dim objPageCount<BR> Set objPageCount = Server.CreateObject("MSWC.PageCounter")<BR> &#039;Increment the counter<BR> objPageCount.PageHit()<BR> Session("siteHits")=objPageCount.Hits()<BR>End Sub<BR>&#060;/SCRIPT&#062;<BR><BR>and I read the Session variable from another page with...<BR> &#060;%= Session("siteHits") %&#062; <BR><BR>whats the go?<BR>Thanks<BR>Zeg

  2. #2
    Join Date
    Dec 1969

    Default RE: Page Counter object and global.asa

    You are recreating the object each time a session starts!<BR><BR>If you want a persistent counter that will survive site resets then you will need to store a counter in a text file or database of some description.<BR><BR>Try creating a simple Access db with 1 table, 1 row, 1 column called "SiteCounter" defined as an integer. <BR><BR>then in session_onstart open a database connection, read in the row and increment "SiteCounter" by 1 - update, then close the connection<BR><BR><BR>If you want a page counter rather than SITE counter then there is a good example using the File System Object (a text file) on 4guys - search for "Creating a Persistent Web Page Counter"<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts