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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I read session cookies in Coldfusion 1

Status
Not open for further replies.

noyes99

Programmer
Jun 25, 2002
38
IN
hi, i am totally new to coldfusion. could someone tell me how do I read session cookies in coldfusion? i used to work with vignette, but i need to do a bit of stuff with cold fusion. any help would be greatly appreciated.

thanks
 
&quot;Session cookies&quot; is a bit of a misnomer. ColdFusion stores session-level variables in server memory. The first time a page in a session-enabled application is requested by a new user, a little bit of memory is allocated for storage of session variables and a countdown is started. Each time the same user requests another page in the same application, the countdown is restarted, but if the countdown ever gets to zero the session &quot;expires&quot; and the server releases the memory associated with that session. You can set the length of the countdown in the <CFAPPLICATION> tag, but a default value and a maximum allowable value are both set in the ColdFusion Administrator.

In use, the Session variables are a distinct variable scope that you can access much like the local scope or the FORM scope. Session variables can be simple variables like strings and numbers, or complex variables like arrays, structures, and query recordsets. Once set, you can access the session variable on subsequent pages but you must always consider that if the user has waited too long between page views, the session variables might disappear.

The main difference between the SESSION scope and other scopes like the FORM scope and local variables (officially called the VARIABLES scope) is that since the Session scope can theoretically be accessed simultaneously by multiple pages, it is considered a &quot;shared&quot; scope and you must surround calls to this scope with locks to both ensure the logical integrity of your code and prevent memory corruption. Whenever you read from a SESSION-scope variable, you must surround the code with a &quot;read-only&quot; lock, and whenever you write to the scope you must use an &quot;exclusive&quot; lock. Keep in mind that some less obvious tags may read or write from the SESSION scope and must be locked, like <cfparam> (needs an exclusive lock if you are providing a default value). Here's some example code:
Code:
  <cflock scope=&quot;SESSION&quot; type=&quot;exclusive&quot; timeout=&quot;10&quot; throwontimeout=&quot;YES&quot;>
    <cfparam name=&quot;SESSION.userloggedin&quot; default=&quot;NO&quot;>
    <cfset SESSION.userArray = ArrayNew(1)>
    <cfset SESSION.userArray[1] = &quot;me&quot;>
    <cfset SESSION.userArray[2] = &quot;you&quot;>
  </cflock>
  <cflock scope=&quot;SESSION&quot; type=&quot;readonly&quot; timeout=&quot;10&quot; throwontimeout=&quot;YES&quot;>
    <cfif SESSIOn.userloggedin>
      <cfoutput>
        #SESSION.userArray[1]#<br />
        #SESSION.userArray[2]#<br />
      </cfoutput>
    <cfelse>
      <cflocation url=&quot;login.cfm&quot;>
    </cfif>
  </cflock>

Hope this helps.

-pcorreia
Did I Help? Vote!
 
thank you. I am a new user, and this has been extremely helpful.

- regards
 
Glad to be of help. Thanks for the star!

Don't hesitate to post any more questions you have as you're learning CF, even if you think they're very basic. Many of us on this forum are more than happy to help out new CF users.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top