Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-26-2002, 12:26 AM   PM User | #1
JustAsking
Regular Coder

 
Join Date: Jun 2002
Location: -27° 28' 22" , 153° 1' 22"
Posts: 135
Thanks: 0
Thanked 0 Times in 0 Posts
JustAsking is an unknown quantity at this point
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
%>
JustAsking is offline   Reply With Quote
Old 07-26-2002, 02:46 AM   PM User | #2
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
you should change this part:

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

the value will depend on where the count directory is.
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:10 PM.


Advertisement
Log in to turn off these ads.