Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Woes w/Sessions

Posted on 2003-02-19
10
Medium Priority
?
200 Views
Last Modified: 2013-12-24
Sessions are not acting as anticipated.
When I go to step 2 then, return to step 1 my entries in step 1 are gone. What am I doing wrong?

<!--- File: application.cfm
        Author: Rob A.
--->      
<!--- Any variables set here can be used by all our pages --->
<CFSET DataSource  = "groupsales">

<!--- Name our app, and enable Client and Application vars --->
<CFAPPLICATION
  NAME="TktWiz"
  SESSIONMANAGEMENT="Yes"
  sessiontimeout="#CreateTimeSpan(0,0,45,0)#"
  setclientcookies="NO">

<CFCOOKIE name="CFID" value="#SESSION.CFID#">
<CFCOOKIE name="CFTOKEN" value="#SESSION.CFTOKEN#">


<!---
  Filename:     wizard.cfm
  by:                   Rob A
--->

<!--- Total Number of Steps in the Wizard --->
<CFSET NumberOfSteps = 3>

<!--- The SESSION.TktWiz structure holds users' entries --->
<!--- as they move through wizard. Make sure it exists! --->
<CFIF (NOT IsDefined("SESSION.TktWiz")) OR (NOT IsDefined("URL.StepNum"))>
  <!--- If structure undefined, create/initialize it --->
  <CFSET SESSION.TktWiz = StructNew()>
  <!--- Represents current wizard step; start at one --->
  <CFSET SESSION.TktWiz.StepNum = 1>
  <!--- We will collect these from user; start blank --->
  <CFSET SESSION.TktWiz.FName  = "">
  <CFSET SESSION.TktWiz.LName   = "">
  <CFSET SESSION.TktWiz.phone  = "">
  <CFSET SESSION.TktWiz.extension = ""> 
  </CFIF>


<!--- If user just submitted information, remember it --->
<CFIF IsDefined("Form.TktWiz")>
  <CFSET SESSION.TktWiz.FName = Form.FName>
  <CFSET SESSION.TktWiz.LName = Form.LName>
  <CFSET SESSION.TktWiz.phone = Form.phone>
  <CFSET SESSION.TktWiz.phone = Form.extension>

  </CFIF>


<!--- If user clicked "Back" button, go back a step --->
<CFIF IsDefined("Form.GoBack")>
  <CFSET SESSION.TktWiz.StepNum = URL.StepNum - 1>
<!--- If user clicked "Next" button, go forward one --->
<CFELSEIF IsDefined("Form.GoNext")>
  <CFSET SESSION.TktWiz.StepNum = URL.StepNum + 1>
<!--- If user clicked "Finished" button, we're done --->
<CFELSEIF IsDefined("Form.GoDone")>
  <CFLOCATION URL="NewTktCommit2.cfm">
</CFIF>


<HTML>
<HEAD><TITLE>Group Registration Wizard</TITLE></HEAD>
<BODY>

<!--- Show title and current step --->
<CFOUTPUT>
  <H1>Group Registration Wizard</H1><BR>
  <p>Step #SESSION.TktWiz.StepNum# of #NumberOfSteps#</p><BR>
</CFOUTPUT>


<!--- Data Entry Form, which submits back to itself --->
<CFFORM
  ACTION="wizard.cfm?StepNum=#SESSION.TktWiz.StepNum#"
  METHOD="POST">
 
  <!--- Display the appropriate wizard step --->
  <CFSWITCH EXPRESSION="#SESSION.TktWiz.StepNum#">
    <!--- Step One: Contact Information --->
    <CFCASE VALUE="1">
      <!--- Get potential counties from database --->
        <cfquery name="GetCounty" datasource="schoolgroups">
        SELECT *
        FROM Counties
        </cfquery>
        <!--- Get potential states from database --->
      <cfquery name="GetState" datasource="schoolgroups">
      SELECT *
      FROM abbrStates
      </cfquery>
      <!--- get todays date and hide it use as date entered --->
        <INPUT
         TYPE="hidden"
         NAME="dateEntered"
         VALUE="<cfoutput>#Now()#</cfoutput>">
      <!--- Show text entry field for first name --->
      <P>What is your first name?<BR>
      <CFINPUT
        NAME="FName"
        SIZE="25"
        REQUIRED="Yes"
        MESSAGE="Please don't leave your first name blank."
        VALUE="#SESSION.TktWiz.FName#">

      <!--- Show text entry field for last name --->
      <P>What is your last name?<BR>
      <CFINPUT
        NAME="LName"
        SIZE="50"
        REQUIRED="Yes"
        MESSAGE="Please don't leave your last name blank."
        VALUE="#SESSION.TktWiz.LName#">
        <P>What is your phone number?<BR>
        <cfinput
            name="phone"
            type="text"
            validate="telephone"
            id="phone"
            REQUIRED="Yes"
        MESSAGE="Please enter your phone number."
            value="#SESSION.TktWiz.Phone#">
            
            <P>What is your extension?<BR>
        <cfinput
            name="extension"
            type="text"
            id="extension"
            value="#SESSION.TktWiz.extension#">
       
 

   
   
    <!--- Step Three: Final Confirmation --->
    <CFCASE VALUE="3">
      You have successfully finished the New Ticket Registration Wizard.<BR>
      Click the Finish button to confirm your registration.<BR>
      Click Back if you need to change anything.<BR>
    </CFCASE>  
  </CFSWITCH>
 

  <P>
  <!--- Show Back button, unless at first step --->  
  <CFIF SESSION.TktWiz.StepNum GT 1>
    <INPUT TYPE="Submit" NAME="GoBack" VALUE="&lt;&lt; Back">
  </CFIF>  
  <!--- Show Next button, unless at last step --->
  <!--- If at last step, show "Finish" button --->
  <CFIF SESSION.TktWiz.StepNum LT NumberOfSteps>
    <INPUT TYPE="Submit" NAME="GoNext" VALUE="Next &gt;&gt;">
  <CFELSE>
    <INPUT TYPE="Submit" NAME="GoDone" VALUE="Finish">
  </CFIF>
</CFFORM>

</BODY>
</HTML>
0
Comment
Question by:RobA
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 7982769
Try the following

<CFAPPLICATION
 NAME="TktWiz"
 sessionmanagement="Yes"
 clientmanagement="Yes"
 setclientcookies="Yes"
 clientstorage="REGISTRY"
 sessiontimeout="#CreateTimeSpan(0,0,45,0)#"
>
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 7982805
Also when you set the session var, you need a lock

<CFLOCK timeout="30" scope="session" type="exclusive" >

 <CFSET SESSION.TktWiz.FName  = "">
 <CFSET SESSION.TktWiz.LName   = "">
 <CFSET SESSION.TktWiz.phone  = "">
 <CFSET SESSION.TktWiz.extension = ""> 

</CFLOCK>


and when you read it, you need another lock

<CFLOCK timeout="30" scope="session" type="readonly" >
     <CFIF ISDEFINED("SESSION.PRODUCT_ID")>
          <CFSET default_product_id = SESSION.PRODUCT_ID >     
     </CFIF>
</CFLOCK>
0
 

Expert Comment

by:eriklee
ID: 7991932
possibly because u said

setclientcookies='No'..
0
[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 

Expert Comment

by:pgobos
ID: 7994170
I tried the following code changes suggested by Hamdy as well as the application changes and it still does not work.

Hamdy did you test this code?



<CFLOCK timeout="30" scope="session" type="exclusive" >

 <CFSET SESSION.TktWiz.FName  = "">
 <CFSET SESSION.TktWiz.LName   = "">
 <CFSET SESSION.TktWiz.phone  = "">
 <CFSET SESSION.TktWiz.extension = ""> 
</CFLOCK>

<!--- If user just submitted information, remember it --->
 
<CFLOCK timeout="30" scope="session" type="readonly" >
<CFIF IsDefined("Form.TktWiz")>
 <CFSET SESSION.TktWiz.FName = Form.FName>
 <CFSET SESSION.TktWiz.LName = Form.LName>
 <CFSET SESSION.TktWiz.phone = Form.phone>
 <CFSET SESSION.TktWiz.phone = Form.extension>
 </CFIF>
 </CFLOCK>
0
 

Author Comment

by:RobA
ID: 7994703
I tried making the appliaction changes and it didn't work.


<!--- Any variables set here can be used by all our pages --->
<CFSET DataSource  = "groupsales">

<!--- Name our app, and enable Client and Application vars --->
<CFAPPLICATION
  NAME="TktWiz"
  SESSIONMANAGEMENT="Yes"
  setclientcookies="Yes"
  clientstorage="REGISTRY"
  sessiontimeout="#CreateTimeSpan(0,0,45,0)#">

<CFCOOKIE name="CFID" value="#SESSION.CFID#">
<CFCOOKIE name="CFTOKEN" value="#SESSION.CFTOKEN#">

0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 7995581
If you run coldfusion on unix, then registry won't work.

Please check coldfusion admin to setting
SESSIONMANAGEMENT and clientmanagement


pgobos :
for sure it's working for me.


The only thing somebody need to investigate about setting cookie CFID and CFTOKEN , when we can do that ? and where we should put this code?

0
 

Expert Comment

by:pgobos
ID: 7998558
Strange I am using Windows 2000 and can't seem to get it to work.  It looks like RobA used a Ben Forta example to run this code .
 The Ben Forta example runs fine and I thought I traced threw it comparing both.

I still cannot find the error in this code.

I do not think CFID and CFTOKEN  tags are even needed in this example.
0
 

Author Comment

by:RobA
ID: 8008314
To Clarify, the "problem" I see is this:

When I submit the info for Step 1 then, goto Step 2 two different things can happen:

1) Click the browser's back button: Step 1 displays previously entered info.

2) Click the application back button: Step 1 is empty.

Is this expected? I would have thought that the application back button would behave similarily to the browser back button?

My perspective/opinion is that you show the user what they entered and change only what is necessary. Not force the user to re-enter ALL the information in the previous step.
0
 

Author Comment

by:RobA
ID: 8064621
So.. is this really a problem or the usual behavior?
0
 
LVL 10

Accepted Solution

by:
substand earned 160 total points
ID: 8076677
it would be the usual behavior, since the browser is involved.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

571 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