I am having a problem with session variables. The values I assign to
them are not being saved when I use any relocate method, either from a
handler or from a template.
I have a handler that redirects to an external site (Twitter), but I
have also tried this when redirecting to internal methods as well and
get the same results.
When I set session variables inside a handler and then call a
cflocation after, the session variables are not saved. It doesn't
matter if I call the cflocation from the handler itself, or from the
layout/view template the handler sets.
I get this behavior when I use cflocation, setNextEvent or the
relocate() method.
Example:
<cffunction name="example" returntype="any" output="false">
<cfargument name="event" required="true">
<cfset var rc = event.getCollection()>
<cfscript>
if (isDefined("rc.test")) {
session.test = rc.test;
}
event.setLayout("Layout.Example");
</cfscript>
</cffunction>
If I call index.cfm?event=my.example&test=mike and then do: <cfdump
var="#session#"> on the Layout.Example.cfm file, I see the correct
value for session.test, the handler sets session.test to "mike" and I
see mike on the page. However, if I do:
<cffunction name="example" returntype="any" output="false">
<cfargument name="event" required="true">
<cfset var rc = event.getCollection()>
<cfscript>
if (isDefined("rc.test")) {
session.test = rc.test;
}
</cfscript>
<cflocation url="http://www.twitter.com">
</cffunction>
I am relocated to Twitter, but if I check back with my page that has
the session dump again, session.test hasn't changed.
The weird part is, if I dump the session to a file just before the
cflocation, the values are correct, but after the cflocation, the
values are not saved and are different from the ones saved in the
file. Something about using a relocation is causing the session
variables not to save. They have the correct values temporarily before
the relocation, but then return to whatever value they were before the
handler was called.
The oddest part is that if the variable has not been set yet (if
session.test doesn't exist), the value will be set the first time I
call the handler and redicrect, but later requests won't save it.
So if I call index.cfm?event=my.example&test=mike when session.test
doesn't exist, the handler correctly sets session.test and relocates
to Twitter. If I check my session dump page, the value is saved and
correct. However, calling index.cfm?event=my.example&test=somethingnew
AFTER session.test exists causes the session variables not to be saved
after a relocation, the value stays "mike" and doesn't change to
"somethingnew", even though if I dump the session right before the
location, the value for test IS "somethingnew" like it should be, but
back to "mike" after the relocation.
Can anyone help with what is causing this? Thank you!