• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Session

Guest
Apr 11, 2007 Apr 11, 2007

Copy link to clipboard

Copied

I am trying to set a session to log attempts, I have a page that displays an Identity question, I need to track how many times the y try to answer it. Can somebody help me. Here is my code.

<cfparam name="session.attempts" default="0">
<cfset session.attempts = StructNew()>
<cfset session.attempts=session.attempts+1>
TOPICS
Advanced techniques

Views

395

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 11, 2007 Apr 11, 2007

Copy link to clipboard

Copied

><cfset session.attempts = StructNew()>
><cfset session.attempts=session.attempts+1>

You cannot use "+" on a structure. If session.attempts is a simple number, remove this line.
<cfset session.attempts = StructNew()>

You might also want to lock the increment statement to prevent race conditions.
<cflock ...>
<cfset session.attempts=session.attempts+1>
</cflock>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 11, 2007 Apr 11, 2007

Copy link to clipboard

Copied

so would it look like this?

<cflock scope="session" type="exclusive" timeout="5">
<cfset attempts = session.attempts>
<cfset session.attempts=session.attempts+1>
</cflock>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 11, 2007 Apr 11, 2007

Copy link to clipboard

Copied

><cfset attempts = session.attempts>
It doesn't look like you're doing anything with the variable "attempts". Try

<cflock scope="session" type="exclusive" timeout="5">
<cfparam name="session.attempts" default="0">
<cfset session.attempts=session.attempts+1>
</cflock>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 11, 2007 Apr 11, 2007

Copy link to clipboard

Copied

ok cool, let me ask you this when this page is called is that when the session starts? and does the session.attempts add 1 everytime the page is called during this session?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 11, 2007 Apr 11, 2007

Copy link to clipboard

Copied

>when this page is called is that when the session starts?
Maybe. It depends. "A new session is created as a result of a request that is not in an existing session". So calling that page might start a new session or it might not.

>and does the session.attempts add 1 everytime the page is called during this session?
Yes. I'm not sure that's what you want. For counting retry attempts I usually use a cfif to check whether the value should be incremented.

<cfif ... some condition>
<cflock..>
...increment value here
</cflock>
</cfif>




Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 11, 2007 Apr 11, 2007

Copy link to clipboard

Copied

LATEST
Thanks for your help, I have a set of IdentityQuestion in my db and I am displaying them randomly, and I am only allowing the user 3 times to answer the question, I will use this session.attempts to track it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation