Hit Counter

Discussion in 'ASP General' started by alfa_beveren, Feb 4, 2004.

  1. alfa_beveren

    alfa_beveren Guest

    How to make a simple Hit Counter ?

    I am old VB Programmer, trying to learn ASP...

     
    alfa_beveren, Feb 4, 2004
    #1
    1. Advertising

  2. alfa_beveren

    Roy Danon Guest

    Hi,
    Create an ASCII file
    Use the FSO Object to open the file, read the number written there.
    Replace it with the num+1 and display the num+1.

    * You can use a database instead

    Roy.

    "alfa_beveren" <> wrote in message
    news:BI7Ub.1607$...
    > How to make a simple Hit Counter ?
    >
    > I am old VB Programmer, trying to learn ASP...
    >
    >
    >
    >
     
    Roy Danon, Feb 4, 2004
    #2
    1. Advertising

  3. alfa_beveren

    Evertjan. Guest

    wrote on 04 feb 2004 in microsoft.public.inetserver.asp.general:
    > On Wed, 4 Feb 2004 15:54:00 +0100, "alfa_beveren"
    > <> wrote:
    >
    >>How to make a simple Hit Counter ?
    >>
    >>I am old VB Programmer, trying to learn ASP...
    >>

    > You nees to use an Application or session variable. In Global.asa add
    > the counter to the On_Start function.


    ============================
    1
    A session variable will not help you.
    It will only count the hits you yourself made in one session.

    =============================
    2
    <%
    if application("MypageHits")="" then
    application("MypageHits")=1
    else
    application("MypageHits")=application("MypageHits")+1
    end if
    response.write application("MypageHits") & "Hits<br>"
    %>

    This will count the hits till the server is reset.
    Not a good option either.

    ==============================
    2
    Use a database or a textfile and
    "read increment write" the number stored there.

    for this you have to read up on databases or look here:

    <http://www.4guysfromrolla.com/webtech/041801-1.shtml>

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 4, 2004
    #3
  4. alfa_beveren

    Roland Hall Guest

    "alfa_beveren" wrote:
    : How to make a simple Hit Counter ?

    <%

    ' Author: Roland Hall
    ' Subject: ASP Hit Counter
    ' Date: Feb. 04, 2004
    ' NS: msnews.microsoft.com
    ' NG: microsoft.public.inetserver.asp.general
    'Filename: hitcounter.asp
    ' Modify: sFile = "drive:path\hitcounter.txt" - IUSR must have change
    rights
    ' Use: Include file in any ASP file to display current hit count
    ' Note: File is automatically created if it does not exists and value set
    to 0

    Sub writeFile(strFile,strHits)
    Const ForWriting=2
    Dim oFS, oFSFile
    Set oFS = Server.CreateObject("Scripting.FileSystemObject")
    Set oFSFile = oFS.OpenTextFile(strFile,ForWriting,True)
    oFSFile.Write(strHits)
    oFSFile.Close
    Set oFSFile = Nothing
    Set oFS = Nothing
    End Sub

    Function readFile(strFile)
    Dim oFS, strHits, oTextStream
    Set oFS = Server.CreateObject("Scripting.FileSystemObject")
    If oFS.FileExists(strFile) = True Then
    Set oTextStream = oFS.OpenTextFile(strFile,1)
    strHits = oTextStream.ReadAll
    oTextStream.Close
    Set oTextStream = nothing
    End if
    Set oFS = nothing
    ReadFile = strHits
    End Function

    Sub getCount()
    Dim sfile, hitCount
    sFile = "drive:path\hitcounter.txt"
    hitCount = readFile(sFile)
    if hitCount = "" Then
    writeFile sFile, "0"
    else
    writeFile sFile, hitCount + 1
    end if
    Response.Write(hitCount)
    End Sub

    getCount
    %>

    This is my test page:

    <%@ Language=VBScript %>
    <%
    Option Explicit
    Response.Buffer = True
    %>
    <html>
    <head>
    <title>Hit Counter</title>
    <script type="text/javascript">
    function cMsg(id, x) {
    var IE = document.all;
    var DOM = document.getElementById && !document.all;
    strX = 0;
    if(IE) {
    if(x == 'center') {
    document.all[id].style.width='100%';
    document.all[id].style.textAlign='center';
    } else {
    document.all[id].style.left = x;
    }
    }
    if(DOM) {
    if(x == 'center') {
    document.getElementById(id).style.width='100%';
    document.getElementById(id).style.textAlign='center';
    } else {
    document.getElementById(id).style.left = x;
    }
    }
    }
    </script>
    </head>
    <body onload="cMsg('hits', 'center')">
    <div id=hits style="position: absolute; top: 35px; font: normal 8pt
    serif"><!--#include virtual="/lab/hitcounter.asp"--> people can't be
    wrong!</div>
    </body>
    </html>

    It works in all of the latest of IE, Mozilla and Opera.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Feb 4, 2004
    #4
  5. alfa_beveren

    Bullschmidt Guest

    <<
    How to make a simple Hit Counter ?

    I am old VB Programmer, trying to learn ASP...
    >>


    Here's something that doesn't even require any ASP knowledge:

    Free tracker from eXTReMe digital
    http://www.extreme-dm.com

    Best regards,
    J. Paul Schmidt, Freelance ASP Web Developer
    http://www.Bullschmidt.com
    ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Bullschmidt, Feb 4, 2004
    #5
  6. alfa_beveren

    Roland Hall Guest

    "Roland Hall" wrote:
    : "alfa_beveren" wrote:
    : : How to make a simple Hit Counter ?
    :
    : <%
    :
    : ' Author: Roland Hall
    : ' Subject: ASP Hit Counter
    : ' Date: Feb. 04, 2004
    : ' NS: msnews.microsoft.com
    : ' NG: microsoft.public.inetserver.asp.general
    : 'Filename: hitcounter.asp
    : ' Modify: sFile = "drive:path\hitcounter.txt" - IUSR must have change
    : rights
    : ' Use: Include file in any ASP file to display current hit count
    : ' Note: File is automatically created if it does not exists and value
    set
    : to 0
    :
    : Sub writeFile(strFile,strHits)
    : Const ForWriting=2
    : Dim oFS, oFSFile
    : Set oFS = Server.CreateObject("Scripting.FileSystemObject")
    : Set oFSFile = oFS.OpenTextFile(strFile,ForWriting,True)
    : oFSFile.Write(strHits)
    : oFSFile.Close
    : Set oFSFile = Nothing
    : Set oFS = Nothing
    : End Sub
    :
    : Function readFile(strFile)
    : Dim oFS, strHits, oTextStream
    : Set oFS = Server.CreateObject("Scripting.FileSystemObject")
    : If oFS.FileExists(strFile) = True Then
    : Set oTextStream = oFS.OpenTextFile(strFile,1)
    : strHits = oTextStream.ReadAll
    : oTextStream.Close
    : Set oTextStream = nothing
    : End if
    : Set oFS = nothing
    : ReadFile = strHits
    : End Function
    :
    : Sub getCount()
    : Dim sfile, hitCount
    : sFile = "drive:path\hitcounter.txt"
    : hitCount = readFile(sFile)
    : if hitCount = "" Then
    : writeFile sFile, "0"
    : else
    : writeFile sFile, hitCount + 1
    : end if
    : Response.Write(hitCount)
    : End Sub
    :
    : getCount
    : %>
    :
    : This is my test page:
    :
    : <%@ Language=VBScript %>
    : <%
    : Option Explicit
    : Response.Buffer = True
    : %>
    : <html>
    : <head>
    : <title>Hit Counter</title>
    : <script type="text/javascript">
    : function cMsg(id, x) {
    : var IE = document.all;
    : var DOM = document.getElementById && !document.all;
    : strX = 0;
    : if(IE) {
    : if(x == 'center') {
    : document.all[id].style.width='100%';
    : document.all[id].style.textAlign='center';
    : } else {
    : document.all[id].style.left = x;
    : }
    : }
    : if(DOM) {
    : if(x == 'center') {
    : document.getElementById(id).style.width='100%';
    : document.getElementById(id).style.textAlign='center';
    : } else {
    : document.getElementById(id).style.left = x;
    : }
    : }
    : }
    : </script>
    : </head>
    : <body onload="cMsg('hits', 'center')">
    : <div id=hits style="position: absolute; top: 35px; font: normal 8pt
    : serif"><!--#include virtual="/lab/hitcounter.asp"--> people can't be
    : wrong!</div>
    : </body>
    : </html>
    :
    : It works in all of the latest of IE, Mozilla and Opera.

    You can see it working here:
    http://kiddanger.com/lab/hitcount.asp

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Feb 5, 2004
    #6
  7. alfa_beveren

    Girish Guest

    My company is BLOCKING this site http://www.extreme-dm.com/ why?
    "Bullschmidt" <-nospam> wrote in message
    news:...
    > <<
    > How to make a simple Hit Counter ?
    >
    > I am old VB Programmer, trying to learn ASP...
    > >>

    >
    > Here's something that doesn't even require any ASP knowledge:
    >
    > Free tracker from eXTReMe digital
    > http://www.extreme-dm.com
    >
    > Best regards,
    > J. Paul Schmidt, Freelance ASP Web Developer
    > http://www.Bullschmidt.com
    > ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Girish, Feb 5, 2004
    #7
  8. alfa_beveren

    Roland Hall Guest

    "Girish" wrote:
    : My company is BLOCKING this site http://www.extreme-dm.com/ why?

    Perhaps their marketing involves UCE but to know for sure, ask your IT
    department.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Feb 6, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    1
    Views:
    438
    Lucas Tam
    Aug 9, 2004
  2. =?Utf-8?B?RWR3YXJkSA==?=

    Hit counter on aspx page

    =?Utf-8?B?RWR3YXJkSA==?=, Mar 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    528
    =?Utf-8?B?RWR3YXJkSA==?=
    Mar 27, 2005
  3. dee

    best way to do hit counter?

    dee, Jul 29, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    410
  4. dee

    hit counter

    dee, Aug 23, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    832
  5. CK
    Replies:
    9
    Views:
    413
    Jerry Rasmussen
    Oct 19, 2006
Loading...

Share This Page