
April 27th, 2005, 01:48 PM
|
 |
EXOH
|
|
Join Date: Nov 2004
Location: corner of methadone and disillusionment
|
|
|
<cfcounter /> (counter script)
Okay, we are currently using a counter script that requires a custom tag (<cfcounter />). This works excellently, but we have come across a problem. What it does is creates a line of text in the code, like <!-- This page has been viewed 1000 times since Jan, 25, 2001. --> . The problem is, the date at the end updates every day. So today it would say April 27, 2005. And then tomorrow it will say April 28, 2005. My question is: What in the script is doing this? Does anyone have any ideas as to what will fix this? Thanks in advance.
PHP Code:
<!---
Cold Fusion Multipage Counter
Version 2.0
1/26/01
Written by:
Adam Stout (Adam@adamarkdesign.com)
ADAMARK Design
www.adamarkdesign.com
This tag is free to use but please drop me a note to let me know you are using it. If you have questions or comments email me at: Adam@adamarkdesign.com
Version History:
1.0 - 1/24/01
Initial Release
2.0 - 1/26/01
I wrote then added a bunch of stuff. Checks and records IP of last user
to prevent reloads from incrementing counter. Also stores and displays
if desired the date the counter was created.
Purpose: Custom Tag That Can Be called from anywhere on the server
and will create a counter fill initialized to the number
you specify.
Installation: Place Counter.cfm in your custom tags directory. Call the tag
in your code with <CF_Counter>. Done.
Required Attributes:
None
Optional Attributes:
Start [Integer] -- Initial counter to this number (used 1st time only) (Default is 5000)
Display [Yes/No] -- Whether to print counter visably or as a comment in the page (Default is Yes)
Date [Yes/No] -- Whether or not to display "since Date" (Default is No)
Mask [Date Mask] -- Date mask for Date if Displayed. (Default is "MMM D, YYYY")
Usage:
Ex. 1
<CF_Counter>
Result: Prints 1000
Ex. 2
<CF_Counter Display = "No">
Result: Prints <!-- This page has been viewed 1000 times. -->
Ex. 3
<CF_Counter Display = "No" Start="5000">
Result: Prints <!-- This page has been viewed 5000 times. -->
Ex. 4
<CF_Counter Display = "No" Date = "Yes">
Result: <!-- This page has been viewed 1000 times since Jan, 25, 2001. -->
--->
<CFPARAM NAME="Display" DEFAULT="Yes">
<CFPARAM NAME="Start" DEFAULT="1000">
<CFPARAM NAME="Date" DEFAULT="Yes">
<CFPARAM NAME="Mask" DEFAULT="MMM D, YYYY">
<CFIF IsDefined("Attributes.Start")>
<CFSET Start = #Attributes.Start#>
</CFIF>
<CFIF IsDefined("Attributes.Display")>
<CFSET Display = #Attributes.Display#>
</CFIF>
<CFIF IsDefined("Attributes.Date")>
<CFSET Date = #Attributes.Date#>
</CFIF>
<CFIF IsDefined("Attributes.Mask")>
<CFSET Mask = #Attributes.Mask#>
</CFIF>
<!--- Figure Out Where the Web Server Root is --->
<CFSET Document_Root = Left(CGI.PATH_TRANSLATED,Len(CGI.PATH_TRANSLATED)-Len(CGI.PATH_INFO))>
<!--- This is the Target Directory where you keep your counters --->
<CFSET CounterFile = DOCUMENT_ROOT & "\Counters\" & Replace(CGI.PATH_INFO,"/", "_","ALL")>
<CFIF FileExists(Variables.CounterFile) IS "False">
<!--- Start Counter at 5000 --->
<CFSET ReadThis = Start - 1 & "| " & "|" & DateFormat(Now())>
<CFSET Initial = Start>
<!--- Success Message --->
<CFOUTPUT>
Congrats. Your Counter File Successfully Created.<BR>
Your counter has been initialized to #Initial#<BR>
To change the counter simply modify the counter file:<BR>
#CounterFile#<BR>
</CFOUTPUT>
<CFELSE>
<!--- Read Counter File --->
<CFFILE ACTION="READ" FILE="#CounterFile#" VARIABLE="ReadThis">
<CFSET FirstTime = "Yes">
</CFIF>
<!--- Seperate Last IP, the Count, and StartDate --->
<CFSET Count = ListGetAt(ReadThis,1,"|")>
<CFSET LastIP = ListGetAt(ReadThis,2,"|")>
<CFSET CreateDate = ListGetAt(ReadThis,3,"|")>
<!--- Increment Counter if not a repeat of the last IP --->
<CFIF CGI.REMOTE_HOST NEQ LastIP>
<CFSET PageViews = Count + 1>
<CFELSE>
<CFSET PageViews = Count>
</CFIF>
<!--- Display as comment ot text Display IS NOT "No" AND --->
<CFIF Display IS NOT "False">
<CFOUTPUT>
#PageViews#<CFIF Date IS "Yes"> since #DateFormat(CreateDate,Mask)#</CFIF>
</CFOUTPUT>
<CFELSE>
<CFOUTPUT><!-- This page has been viewed #PageViews# times<CFIF Date IS "Yes"> since #DateFormat(CreateDate,Mask)#</CFIF>. --></CFOUTPUT>
</CFIF>
<!--- Set caller variables for use is wanted --->
<CFSET Caller.PageViews = PageViews>
<CFSET Caller.CreateDate = DateFormat(CreateDate,Mask)>
<!--- Record New Count and IP --->
<CFSET WriteThis = PageViews & "|" & CGI.REMOTE_HOST>
<!--- Insert Date if being initialized --->
<CFIF IsDefined("FirstTime")>
<CFSET WriteThis = WriteThis & "|" & DateFormat(Now())>
<CFELSE>
<CFSET WriteThis = WriteThis & "|" & CreateDate>
</CFIF>
<!--- Output the text file --->
<CFFILE ACTION="WRITE" FILE="#CounterFile#" OUTPUT="#WriteThis#" ADDNEWLINE="No">
|