Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

a cold fusion counter ?

Posted on 2000-03-17
19
Medium Priority
?
450 Views
Last Modified: 2013-12-24
How to write a cold fusion counter script ?
0
Comment
Question by:tanc02
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
  • +2
19 Comments
 
LVL 37

Expert Comment

by:meverest
ID: 2630086
<cfset application.thispagecount = application.thispagecount+1>

<cfoutput>
Now this page has been accessed #application.pagecount# times!
</cfoutput>

make sure that you have application variable support enabled.
0
 
LVL 1

Author Comment

by:tanc02
ID: 2630253
How do I know whether my cold fusion can have
application variable support enabled.

Can you tell me how to set it step by step ?
I have Cold Fusion 4.5 eval version
0
 
LVL 1

Author Comment

by:tanc02
ID: 2630272
In PERL, I have to lock and unlock the counter
file. How about in Cold Fusion ?
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 
LVL 37

Expert Comment

by:meverest
ID: 2630701
from memory, it is enabled in the cfapplication tag.

check the cf docs, if you can't find it, remind me on monday and i will check for you.

cheers.
0
 
LVL 1

Author Comment

by:tanc02
ID: 2631671
Can you tell me how ? I couldn't find  the info thanks !
0
 
LVL 1

Expert Comment

by:chaduka
ID: 2631673
There is a small counter solution that makes use of a number field in a database.

It's like you have your datasource, say an MS Access file, called "myDSN" in which you have a table called "counters" and a field called "myMainCounter", which is a number field.

Then you will do it like this:

<cfquery name="visitorCount" datasource="myDSN">
 select myMainCounter from counters
</cfquery>

Now to display this value, you will do it like this:

<cfoutput>
You are visitor #int(visitorCount.myMainCounter)#
</cfoutput>

Now you will have to increment this value, do like so:

<cfquery name="visitorCount" datasource="myDSN">
 update counters set myMainCounter = #IncrementValue(int(visitorCount.myMainCounter))#
</cfquery>
0
 
LVL 1

Expert Comment

by:chaduka
ID: 2631676
Oooops!! The update query should be like this:

<cfquery name="updateVisitorCount" datasource="myDSN">
 update counters set myMainCounter = #IncrementValue(int(visitorCount.myMainCounter))#
</cfquery>

I had forgotten to change the name of the query! My apologies!

(the bad side of Ctrl-C/Ctrl-V!!) :))
0
 
LVL 5

Expert Comment

by:nathans
ID: 2632590
If you can't get these to work and want a solution written for you I will do it.

Nathan Stanford
Mr. ColdFusion

0
 
LVL 37

Expert Comment

by:meverest
ID: 2632679
check the docs for <cfapplication> for additional detail...

<CFAPPLICATION NAME="Name"
    CLIENTMANAGEMENT="Yes/No"
    CLIENTSTORAGE="Storage Type"
    SETCLIENTCOOKIES="Yes/No"
    SESSIONMANAGEMENT="Yes/No"
    SESSIONTIMEOUT=#CreateTimeSpan(days, hours,
      minutes, seconds)#
    APPLICATIONTIMEOUT=#CreateTimeSpan(days, hours,
      minutes, seconds)#>

the attribute you are interested in is:

APPLICATIONTIMEOUT
Optional. Enter the CreateTimeSpan function and the values you want in days, hours, minutes, and seconds, separated by commas to specify the lifespan of any application variables that are set. The default value is specified in the Variables page of the ColdFusion Administrator.

in CF administrator (usually http://127.0.0.1/CFIDE/Administrator/index.cfm) choose 'variables' from the menu and make sure application variables is checked.

for example:

<cfapplication name="MyApp" APPLICATIONTIMEOUT=#CreateTimeSpan(365, 0, 0, 0)#>

this will allow the application variable to remain static for 1 year with no activity.

cheers.



0
 
LVL 5

Expert Comment

by:nathans
ID: 2660862
Are you still looking for an answer?  tanc02 if not award your points to one of the above???
0
 
LVL 1

Author Comment

by:tanc02
ID: 2661191
Adjusted points from 5 to 20
0
 
LVL 1

Author Comment

by:tanc02
ID: 2661192
nathans :

May I see you solution and can you tell me how to lock/unlock a file ?

Points increase to 20
0
 

Expert Comment

by:samphi
ID: 2664463
Hi,

For unlock what ?
an access file ? (.lbd)
if yes, try :
#cfusion_dbconnections_flush()#

Phil
0
 
LVL 1

Expert Comment

by:chaduka
ID: 2665034
.eh? wazzat, samphi?
0
 
LVL 1

Author Comment

by:tanc02
ID: 2665070
to lock mdb file
0
 
LVL 5

Expert Comment

by:nathans
ID: 2669359
<!---
No need to tell it which page it is coming from it will take care of that for you.

Your Database Needs of you can change the names to fit your needs.

datasource: counter
Table: counter
Cols: PageName
      hits

Nathan Stanford
Mr. Coldfusion
Check Out my ColdFusion Tips Plus e-ZINE
http://www.nsnd.com/cftips
 --->

<cfset PageName = #cf_template_path#>
<cftransaction>

<cfquery name="CountHits" datasource="counter">
      SELECT * FROM counter
      WHERE PageName  = '#PageName#'
</cfquery>

<CFIF #CountHits.recordcount# is 0>
 <CFQUERY name="makePageName" datasource="counter">
  INSERT INTO counter (`PageName`, `hits`)
  VALUES ('#PageName#', 1)
</cfquery>
1
<CFELSE>
<cfoutput>
 #CountHits.hits#
</cfoutput>
<CFSET newhits = (CountHits.hits + 1) > 
 <CFQUERY name="updatehits" datasource="counter">
  UPDATE counter
  SET hits = #newhits#
  WHERE PageName = '#PageName#'
 </cfquery>
</CFIF>
</cftransaction>

0
 
LVL 1

Expert Comment

by:chaduka
ID: 2669459
Ey, on that note Nathans -- I notice in your INSERT query:

<CFQUERY name="makePageName" datasource="counter">
  INSERT INTO counter (`PageName`, `hits`)
  VALUES ('#PageName#', 1)
</cfquery>

...you have backticks/backquotes in the table field names as in `PageName`. What do SQL specs. say regarding the use of these in INSERT/UPDATE queries? Doesn't this have any side effects elsewhere as in some DBMs?
0
 
LVL 5

Expert Comment

by:nathans
ID: 2669565
Sorry, take out the Backticks... it was working for me so I forgot they were there.

Thanks for letting me know.

By the way I am planning to write a ColdFusion Tips Plus (javascript as well) book if anyone is interested email me and let me know at
nathan@nsnd.com

Nathan Stanford
Mr. ColdFusion
http://www.nsnd.com/cftips
0
 
LVL 5

Accepted Solution

by:
nathans earned 60 total points
ID: 2681608
You have the answer and I am posting this as an answer to get you to respond on the above choices we have given you.
0

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question