Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    -27 28' 22" , 153 1' 22"
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP Hit Conter script

    I got this ASP script from http://www.asp101.com/samples/counter.asp
    and it works exactly how it should. But I am trying to get the count file it creates to be in a specific folder. By default the count file created is where the file doing the including is located. I am not sure what needs changing. This has come about because the host of the web server will not give write permission to a whole directory and only to a folder created for the counter file. Can anyone help?

    <%
    ' Declare our vaiables
    Dim objFSO, objCountFile ' object vars for FSO and File
    Dim strCountFileName ' filename of count text file
    Dim iCount ' count variable
    Dim bUseImages ' boolean whether or not to use images
    Dim I ' standard looping var


    ' Determine whether to use images or plain text
    ' You could just set this to True or False instead
    bUseImages = CBool(Request.QueryString("images"))

    strCountFileName = Server.MapPath(Request.ServerVariables("SCRIPT_NAME") & ".cnt")

    ' Create FileSystemObject to deal with file access
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

    ' Open the file as a text stream (1 = ForReading, True = Create)
    Set objCountFile = objFSO.OpenTextFile(strCountFileName, 1, True)

    ' Read the current count from the file
    If Not objCountFile.AtEndOfStream Then
    ' Set value to contents of the file
    iCount = CLng(objCountFile.ReadAll)
    Else
    ' If no file exists or it's empty start at 0
    iCount = 0
    End If

    ' Close the file and destroy the object
    objCountFile.Close
    Set objCountFile = Nothing

    ' Increment the count
    iCount = iCount + 1

    ' Overwrite existing file and get a text stream to new one
    Set objCountFile = objFSO.CreateTextFile(strCountFileName, True)

    ' Write updated count
    objCountFile.Write iCount

    ' Close the file and destroy the object
    objCountFile.Close
    Set objCountFile = Nothing

    ' Destroy the FSO object
    Set objFSO = Nothing

    If bUseImages Then
    ' Loop through the count integer showing each digit
    For I = 1 to Len(iCount)
    ' Output the IMG tag using the right digit
    Response.Write "<img src=""./images/digit_"
    Response.Write Mid(iCount, I, 1)
    Response.Write ".gif"" alt="""
    Response.Write Mid(iCount, I, 1)
    Response.Write """ width=""20"" height=""27"" />"
    Next 'I
    Else
    ' No image wanted just show the variable
    Response.Write iCount
    End If
    %>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    you should change this part:

    strCountFileName = Server.MapPath(Request.ServerVariables("SCRIPT_NAME") & ".cnt")

    the value will depend on where the count directory is.


  •  

    Posting Permissions

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