Link to home
Start Free TrialLog in
Avatar of Elizabeth2
Elizabeth2Flag for United States of America

asked on

How do I extend a users session and session variables in ColdFusion?

I have a ColdFusion application that has a form that uses session variables to prepopulate a form based on the user login ID and also store form input, in case of an error, the user will not lose the form data. However, I've now been requested to extend the session and login session time so that the user who begins to fill out the form, gets distracted by a phone call that takes over an hour, will not lose his/her data when they come back to continue filling out the form. Can someone help me to understand how this is done in CF?

Thank you.
Avatar of erikTsomik
erikTsomik
Flag of United States of America image

you can try something like this
<cflock scope="session" type="readonly" timeout="5">
<cfset Variables.session =
Duplicate(session)>
</cflock>

http://coldfusion.sys-con.com/node/41649
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i would just store the values in the application scope
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Elizabeth2

ASKER

Thank you both for your suggestions. Unfortunately, I know just enough to get myself in trouble. I'm not sure I know "how" to do either of these suggestions.

Attached is my Application.cfm. Could I just extend the session timeout from "20" to "120?" And then extend the cflock timeout of "15" to "120?" Would that accomplish the goal of allowing a user to come back an hour later and continue to fill out his form?

Are there any pitfalls to extending the session timeout? These clients use these forms several times per day, so I'm thinking they would be best left unchanged, but I told my boss I'd check into extending the sessions. If I could give a good reason why not to change the current settings, that would avoid any additional complications that I may not know how to handle.

What do you think?

elizabeth
<cfapplication name='xxxxxxx' clientmanagement='yes' sessionmanagement='yes' setclientcookies='yes' setdomaincookies='no' sessiontimeout="#CreateTimeSpan(0,20,0,0)#">


<!--- Finds the number of sessions being currewnt in use, and displays them where ever using the page <cfinclude template="/users_count.cfm"> --->
<cflock timeout="15" scope="APPLICATION" type="EXCLUSIVE"> 
    <cfif NOT isDefined("Application.UsersInfo")>
          <cfset Application.UsersInfo = StructNew()>
    </cfif> 
</cflock>
<cflock name="#CreateUUID()#" timeout="15" type="EXCLUSIVE">
      <cfset user_cfid = Evaluate(CFID)>
      <cfset user_time = Now()>
</cflock>
<cflock scope="APPLICATION" type="EXCLUSIVE" timeout="15">
 <cfif NOT StructKeyExists(Application.UsersInfo, user_cfid)>
  <cfset temp = StructInsert(Application.UsersInfo, user_cfid, user_time)>
 </cfif>
</cflock>
<cflock scope="APPLICATION" type="EXCLUSIVE" timeout="15">
 <cfloop collection="#Application.UsersInfo#" item="itmUser">
  <cfif
   Evaluate(DateDiff("n", StructFind(Application.UsersInfo, itmUser), Now())) GT 10>
    <cfset StructDelete(Application.UsersInfo, itmUser)>
  </cfif>
 </cfloop>
</cflock>

<!--- Logs user out once browser is closed --->
<cfif IsDefined("Cookie.CFID") AND IsDefined("Cookie.CFTOKEN")>
  <cfset Variables.cfid_local = Cookie.CFID> 
  <cfset Variables.cftoken_local = Cookie.CFTOKEN> 
  <cfcookie name="CFID" value="#Variables.cfid_local#"> 
  <cfcookie name="CFTOKEN" value="#Variables.cftoken_local#"> 
</cfif>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> I totally with SidFishes' answers

   Argh.  Trying to do too many things at once.  That should read "I totally _AGREE_ with SidFishes' answers"
Great help! Thank you so much