Skip to main content
Inspiring
April 23, 2008
Question

Sharing Application Variables

  • April 23, 2008
  • 3 replies
  • 431 views
I have an Application.cfm in the root of my site called App1. I have a directory in this site called Signup with an Application.cfm named App2, I would like App2 to check my Session.LoggedIn variable of the App1 application. Is this possible to do? If so how, i have been racking my brain on this for a few days. Thanks in advance!
This topic has been closed for replies.

3 replies

BKBK
Community Expert
Community Expert
April 24, 2008
App2 needs to see if that SESSION.MYACCOUNT variable IsDefined BUT when I tried to check it, it is looking in the App2 sessions not App1, how do I look in App1 for the SESSION.MYACCOUNT?

You can't. Sessions are privately owned by applications. App2 cannot read App1's session variables.

The following strategy will work. Assume the location of App1's Application.cfc file is wwwroot/app1/. Then add the 'extends' attribute to App2's Application.cfc file, as follows

<cfcomponent extends="app1.Application" ... etc>

App2 can now have access to App1's session variables. However, this is not a sweet structure, as it defeats the purpose of separate applications.

pflynn02Author
Inspiring
April 23, 2008
Here is exactly what im trying to do, im not sure I understand your example...

App1 has a variable called : SESSION.MYACCOUNT

App2 needs to see if that SESSION.MYACCOUNT variable IsDefined BUT
when I tried to check it, it is looking in the App2 sessions not App1, how do I look in App1 for the SESSION.MYACCOUNT? Thanks...
Inspiring
April 23, 2008
pflynn02 wrote:
> I have an Application.cfm in the root of my site called App1. I have a
> directory in this site called Signup with an Application.cfm named App2, I
> would like App2 to check my Session.LoggedIn variable of the App1 application.
> Is this possible to do? If so how, i have been racking my brain on this for a
> few days. Thanks in advance!
>

A template has access to the application scope defined by the name given
in the <cfapplication name="..."> tag or the this.name of a an
Application.cfc

A template can declare <cfapplicaiton ...> more then one time. So you
can do something like this in a specific template to combine the two
application scopes.

<cfapplication name="App1"...>

<cfset variables.localVariable1 = application.applicationOneVar>

...

<cfapplication name="App2"...>

<cfset variables.localVariable2 = application.applicationTwoVar>


<cfif variables.localVariable1 = variables.localVariable2>
<!--- Do stuff with the comparison --->
</cfif>