Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application session

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0


Can someone give me an example of setting application, session and client variables in one template and reference them in another?

 
there is more that one way to do that; here is my way that I think is quite code efficient:


<!--- application.cfm --->

<!--- make the session, application, and client management available to the application --->
<cfapplication
name=&quot;ApplicationName&quot;
sessionmanagement=&quot;Yes&quot;
setclientcookies=&quot;Yes&quot;
sessiontimeout=&quot;#CreateTimeSpan(0,0,20,0)#&quot;
applicationtimeout=&quot;#CreateTimeSpan(2,0,0,0)#&quot;
clientmanagement=&quot;Yes&quot;>

<!--- set the session variables... --->
<!--- I create them as a structure because I can easily then read them and put them in any other scope --->
<cfif NOT IsDefined(&quot;session.stSessionData&quot;)>
<cflock scope=&quot;session&quot; timeout=&quot;30&quot; throwontimeout=&quot;No&quot; type=&quot;exclusive&quot;>
<cfscript>
session.stSessionData = StructNew();
StructInsert(session.stSessionData, &quot;message&quot;, &quot;Hi you!&quot;, 1);
</cfscript>
</cflock>
</cfif>


<!--- loop the structure and dynamically create variables using the the key values and put them in the request scope --->
<cflock scope=&quot;session&quot; timeout=&quot;30&quot; throwontimeout=&quot;Yes&quot; type=&quot;readonly&quot;>
<cfloop collection=&quot;#session.stSessionData#&quot; item=&quot;i&quot;>
<cfscript>
&quot;request.#i#&quot; = session.stSessionData[&quot;#i#&quot;];
</cfscript>
</cfloop>
</cflock>




<!--- any other template controled by the above application template such as index.cfm --->

<cfoutput>#request.message#</cfoutput>


Sylvano
dsylvano@hotmail.com
 
Thanks.

Is the session session variable page and client page and application page all done on seperate pages??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top