Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Needs Help With Invisible Page Counter
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Needs Help With Invisible Page Counter

 Post Reply Post Reply
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Needs Help With Invisible Page Counter
    Posted: 04 August 2005 at 2:21pm
I have code for a visible page counter. I'd like to be able to create a invisible page counter that the public cannot see on the home page. Then I'd like to be able to add an administrative password protected web page that will allow me to see the page counter for the home page. Could someone please help me to write the code for two different web pages (1. Invisible page counter for the home page 2. Visible page counter for me to view in an admin area).
 
Here's the code that I have for a page counter that people can see:\
 
<%
Dim strPath, File, file2, x,liCount, j ,resfile, d, i ,fl
strPath = "D:\inetpub\wwwroot\mywebsite.com\database\counter.txt"
Set File = Server.CreateObject("Scripting.FileSystemObject")
set file2=File.OpenTextFile(strPath)
x=file2.readline
set resfile = File.createTextFile (strPath)

resfile.writeline(x+1)

liCount=Cstr(x+1)
j = Len(liCount)
d=6 - j
 

%>
<%
 
        For i=1 to d step 1
         Response.Write ("<IMG SRC='DG0.gif'>")

        Next
  For  i=1 to j step 1
   fl="DG" + Mid(liCount, i , 1) + ".gif"
  

   Response.Write ("<IMG SRC=") & (fl) & ">"

 Next
%>
 <B><font=ARIAL size="22">Visitors
      since May 18, 2003.</FONT></B>
<%
 
%>
Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 04 August 2005 at 4:17pm
Here's code I use for an invisible page counter named after the page it's on. It only displays if the page is called with ?counter=y or ?counter=yes appended to the url. It can be added to any page with an include without having to mess with the internals for any particular page.

Other variations I've done have only displayed if the request came from one of my fixed ip's or if an admin cookie had been set.

<%

Function fncPageViewCounter(ByVal strTextCounterFile)

' Increments a page view text file containing 1 line with the numbers of page views on it.
' Depending upon how your host has implemented FSO, it may error out on first execution.
' Refreshing the page should clear the error

     Dim objFSO           ' FileSystemObject
     Dim objTS            ' TextStreamObject
 
     Dim strFileName      ' Counter text File Name
     Dim intOldCount
     Dim intNewCount
  
 
     strFileName = Server.MapPath(strTextCounterFile)
 
 
     Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
 
     If objFSO.FileExists(strFileName)  Then
          Set objTS = objFSO.OpenTextFile(strFileName, 1)
     Else
          Set objTS = objFSO.CreateTextFile(strFileName, True)
     End If
    
     If Not objTS.AtEndOfStream  Then
          intOldCount = objTS.ReadAll
     Else
          intOldCount = 0
     End If
 
     objTS.Close
   
     intNewCount = intOldCount + 1
   
   
 ' Write intNewCount value back to text file
 
     Set objTS = objFSO.CreateTextFile(strFileName, True)
     objTS.Write intNewCount
 
     objTS.Close
     Set objFSO = Nothing
     Set objTS = Nothing
     
    fncPageViewCounter = intNewCount

End Function



'Determine the page the footer is currently included in
'and strip the .asp extension to name the counter
'
'to increment the page counter for that page

dim strPageID

strPageID = Replace(Request.ServerVariables("PATH_INFO"), ".asp", "") & ".txt"

%>

<!--
Include these tags on the page so the browser doesn't
show the page from it's cache which wouldn't increment the
page counter.
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
    <META HTTP-EQUIV="EXPIRES" CONTENT="0">
-->

<div align="center" style="color:#000000; font-size:75%;">
<% If Lcase(Request.QueryString("counter")) = "y"  OR Lcase(Request.QueryString("TestFlag")) = "yes"  Then %>
    <p class="countertext"><%=fncPageViewCounter(strPageID)%></p>
    <% Else
        fncPageViewCounter(strPageID)
        End if
    %>
</div>



To view the counter on another page, you just have to open and read the text file - pagefilename.txt - located in the same directory as the page.




Edited by dpyers - 04 August 2005 at 4:36pm

Lead me not into temptation... I know the short cut, follow me.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.