Coldfusion Lud Awareness

I read about CF Scopes, and CFC areas and their consequences are convenient for me ( more here ), however, when I search for CF areas, it almost always refers in the context of CFC. Therefore, I was hoping for some clarification around the areas on the CFM pages. I work with CF 9/10, so I’m really interested in how areas work in these versions.

  • What areas are available on the CFM page - do CFM pages have the same concurrency problems that might occur elsewhere, or are the variables copied on the CFM page tied to the scope of this particular request?

  • If I include the line <cfset myVar = 10 /> on the CFM page, in which area will it be included? Is there a risk that other users on the same page will gain access to this variable or other cfm pages accessible to it?

thanks

+1
source share
2 answers

Almost all areas except 'THIS' are available on CFM pages.

variables without a space declared on the CFM page can be called directly or can be called with the VARIABLES area prefix.

eg:

 <cfset varA = 'someValue'/> 

can also be written as

 <cfset VARIABLES.varA = 'something' /> 

To my knowledge, if you do not create a singleton (CFC only) and place it in the application area, you never run the risk of sharing variables with other users. This is also true if you are not careful in correctly defining local variables in CFC functions.

On the CFM page, each user request has its own processing flow and never intersects with another user request. Thus, the variables are tied only to the scope of this particular request.

if you want the variables to be used by all users requesting the page, you can put them in the APPLICATION area.

I did not quite understand your second question. if you can clarify, maybe I can add more to my answer.

Update

This code will help you answer 2 questions.

 <cfscript> function a(){ _a = 20; WriteOutput("Inside function:"&variables['_a']); WriteOutput("Inside function:"&variables['_b']); } _b = 30; a(); WriteOutput('outside function:'&variables['_a']); </cfscript> 

Exit

Internal function: 20
Internal function: 30
external function: 20

+2
source

This page gives a good explanation of the available areas.

If you look closely enough, you will find more information about what will happen if you do not cover the variables. The bottom line is that your code will work successfully, but less efficiently. The reason is that ColdFusion will try to find the right volume. It checks certain scopes in a specific order. This order is somewhere, I just could not find it quickly.

For your second question

 <cfset myVar = 10> 

puts the variable myVar in the variable area.

Regarding the fact that one user changes the variables that affect other users, I believe that the only area of ​​risk is the area of ​​application. However, with modern browsers, one user can mess up their own session variables. I have seen that.

Another way that variables can be inadvertently changed is through functions. If you want your variables to be local to the function, you need to use the var keyword when creating them. In later versions of CF, there is a local scope that does the same thing.

Personally, I use all my variables except the variable scope.

+1
source

All Articles