Skip to main content
December 14, 2011
Question

Session variable being lost between parent and include file

  • December 14, 2011
  • 2 replies
  • 1059 views

I am running into the following scenario: Page 1 includes page 2, on both pages a session variable is returned to the screen. On occasions, page 2 throws an error on the session variable even though it was successfully called on page 1.

It only happens occassionally, and is very difficult to recreate in order to debug it in realtime. Has anyone run into something like this before? Thanks!

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
December 15, 2011

semi star gazer wrote:

I am running into the following scenario: Page 1 includes page 2, on both pages a session variable is returned to the screen. On occasions, page 2 throws an error on the session variable even though it was successfully called on page 1.

It only happens occassionally, and is very difficult to recreate in order to debug it in realtime. Has anyone run into something like this before? Thanks!

I suspect it has less to do with page-inclusion, more to do with the code on page 2. Suppose, instead of using cfinclude, you had copied the code from page 2 into page 1, and made 1 page of it. Then the error would still have occurred. That's at least my theory.

Have a look at how the code in page 2 handles the session. There is bound to be something not quite right about it. What kind of error do you get anyway?

Runtime debugging can be as simple as this:

<cftry>

<cfinclude template="page2.cfm">

<cfcatch type="any">

<cfdump var="#cfcatch#"><cfabort>

</cfcatch>

<cftry>

Inspiring
December 15, 2011

Regarding:

I suspect it has less to do with page-inclusion, more to do with the code on page 2

I share that suspicion.  The scenario in the OP is different than what I described earlier.  Given that the problem appears to be intermittent, I suspect that something is happening to the variable, inside some conditional logic code.

Inspiring
December 15, 2011

Same general idea but different details.  It happens when the user is running the same application in different browser windows or tabs.  It's all the same session so on occasion activity in Window B overwrites session variables written in Window A.

Sean Coyne
Participating Frequently
December 15, 2011

Sounds like you need to use cflock to prevent multiple requests from accessing those variables at the same time.