Skip to main content
Known Participant
September 27, 2010
Question

will variables lose state after cflocation is executed

  • September 27, 2010
  • 2 replies
  • 1387 views

After the following two statements are executed,

<cflocation url="index.cfm?action=#action#" addtoken="No">

<cfabort>

will the variables lose state?

Should I do the following?

<cflock timeout="20" scope="Session" type="Exclusive">

<cfif IsDefined(#Session.status#)>

    <cfoutput>Session.status #Session.status#</cfoutput>

<cfelse>

      <cfset Session.status = "Next">

</cfif>

</cflock>

<cflocation url="index.cfm?action=#action#" addtoken="No">

<cfabort>

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
September 29, 2010
will variables lose state after cflocation is executed

So long as you enabled the use of sessions, and the client accepts cookies, session state will be maintained.

Inspiring
September 27, 2010

<cflocation> immediately sends a clientside 302-redirect, and terminates the currently processing CF request.

There's no point in outputtting anything before a 302-redirect as only the header is send to the client.

It's not really clear from your post what exactly you're asking, because as far as I can tell your two code blocks are unrelated to each other, so it's hard to say "that one is better than the other one".  It's like saying apples are better than orangutans, without explaining "better at what?"

It's probably worth while reading the docs on <cflocation>:

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7cac.html

--

Adam

ilssac
Inspiring
September 27, 2010

In addtion to Adam's comments about <cflocation...>  AND even though this code probably has little relevance before a <cflocation...> you may want to study up isDefined(), session scope and locking.

Issue One

Unless you are running code on an ancient ColdFusion server, i.e. pre version 6.  (The current version is version 9).  You probably do not need to be locking session access like that.  At least I would see little need for it.

Issue Two

Your isDefined() should be <cfif isDefined("session.status")>.  In your version the function is going to look for variables named after any string stored in the session.status variable, apparently strings such as "Next".