Server Time:
Friday May 9 2008 04:11 PM  
Your Time:
  
HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

The CFAPPLICATION tag and Session variables..
by: John Bartlett
Email this tutorial to a friend Display Printer Friendly Format
[Download in PDF Format] [Download in FlashPaper Format]

In order to use session variables, first you have to instruct the Cold Fusion server that you wish to use them.

<cfapplication name="PickSomeUniqueName"
               ClientManagement="No"
               SessionManagement="Yes"
               SessionTimeout="#CreateTimeSpan(0,0,30,0)#"
               SetClientCookies="Yes">
It would be best to place this inside your Application.cfm file, otherwise you will have to add it in each of your templates before you refrence any session variables. The "SessionTimeout" field defines how long to wait before removing the user's session variables from the system's memory. The syntax is SessionTimeout="days,hours,minutes,seconds". In this case, if the user does not perform any action on your site within 30 minutes, their session variables will dissapear.

Once you set the CFAPPLICATION tag, simply prefix any variables that you want to be access across multiple pages with "session.". For example, once you set the variable "session.userid", all of your pages can use it.

Keep in mind that you'll have to code in some sort of check to see if the session variables have expired. You can either define them with a default value or if the session variable doesn't exist, redirect them to your login page.

<!--- Check to see if the session variable exists, if not set it. --->
<CFPARAM name="session.IsLoggedIn" default="N">


<!--- Check to see if the session variable exists, 
      if not redirect them to the login page --->
<CFIF IsDefined("session.IsLoggedIn") EQUAL "No">
  <CFLOCATION URL="/login.cfm">
</CFIF>
Looking for more ColdFusion tutorials? Visit my ColdFusion Tips & Tricks website!

Date added: Tue. September 17, 2002
Posted by: John Bartlett | Views: 54709 | Tested Platforms: CF5 | Difficulty: Beginner
Categories Listed: Best Practices

HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

Please rate this tutorial:
5 Stars 4 Stars 3 Stars 2 Stars 1 Stars
Comments on this tutorial
Read previous comments on this particular tutorial
kill session
i need you help in how to kill session .. i need it in my senior project.
Posted by: reham
Posted on: 05/25/2005 02:11 AM
Clearing a session
http://www.cflib.org/udf.cfm?ID=1097
Posted by: John Bartlett
Posted on: 05/25/2005 02:31 AM
is session end?
i want to kill session when my browser closed, i do not know how to do it.
need help please
Posted by: zaza
Posted on: 07/10/2006 03:00 AM
Post a new comment on this tutorial
post a new comment on this particular tutorial
Your Name:
Your Email:
Comment Title:
Comments:
Key Phrase:
 
Skyscrapper Banner Advertisement
Daily Razor - ColdFusion Hosting

You are 1 of 418 active sessions! | Privacy | Company
Copyright © 2002 EasyCFM.Com, LLC. (Easy ColdFusion Tutorials) All Rights Reserved
All other trademarks and copyrights are the property of their respective holders.
ColdFusion Hosting ColdFusion Hosting
ADD TO:
Blink
Del.icio.us
Digg
Furl
Google
Simpy
Spurl
Y! MyWeb