Session variable not being set immediately after CFSET session.var = "data"
Hello, everyone.
Got a real head scratcher (at least, for me it is.)
Just experimenting a little bit, this isn't project related (yet), but something I'd like to code as reusable for future projects.
I'm attempting to write code that will clear session variables when the browser is closed, -AND- disassociate the session variables from the client by altering and expiring the cfid and cftoken cookies.
In my Application.cfc, I have the following:
onSessionStart:
<cfif NOT StructKeyExists(session,"app")><cfinvoke component="components" method="setDirs" returnvariable="session.app"></cfif>
<cfset oRequest = getPageContext().getRequest()>
<cfset session.cookies = oRequest.getHTTPRequest().getCookies()>
<cfcookie name="cfid" value="#session.cfid#">
<cfcookie name="cftoken" value="#session.cftoken#">
onSessionEnd:
<cfloop index="local.cookiename" list="cfid,cftoken,cfmagic"><cfcookie name="#local.cookiename#" value="" expires="now"></cfloop>
In the page that loads, I have:
<cfset session.cookies = getPageContext().getRequest().getHTTPRequest().getCookies()>
<cfoutput>
<cfloop index="idx" array="#session.cookies#">#idx.getName()# = #idx.getValue()# - Expires: #idx.getMaxAge()#</cfloop>
</cfoutput>
The above is where the error message "Cookies undefined in Session" appears. Didn't I just set session.cookies, twice?
Thank you,
^_^
