6 Replies Latest reply on Apr 11, 2007 6:38 PM by gill1723

    Session

    gill1723
      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>
        • 1. Re: Session
          cf_dev2 Level 1
          ><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>
          • 2. Re: Session
            gill1723 Level 1
            so would it look like this?

            <cflock scope="session" type="exclusive" timeout="5">
            <cfset attempts = session.attempts>
            <cfset session.attempts=session.attempts+1>
            </cflock>
            • 3. Re: Session
              cf_dev2 Level 1
              ><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>
              • 4. Re: Session
                gill1723 Level 1
                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?
                • 5. Session
                  cf_dev2 Level 1
                  >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>




                  • 6. Re: Session
                    gill1723 Level 1
                    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.