I have a need to see all session scope for all logged in users in ColdFusion2018

Viewed 73

I start with this find;

<cfscript>
    app = application.getApplicationSettings().name;
    sessionCollection = application.sessionTracker.getSessionCollection(app);
</cfscript>

and then attempt to loop thru the collection;

<cfloop collection="#sessionCollection#" item="i">
    #StructFind(i, 'CurrentAction')#
</cfloop>

which fails with; You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.

I have tried

#CurrentAction[i]#

which fails with; Variable CURRENTACTION is undefined.

when I know for a fact it exists (https://ibb.co/ZJwsKFS)

Ive tried dot notation as well.

The purpose is to identify an ajax listener activity for one user, and affect an action on another specific user as a response. I am under the impression I can send an action by sessionID end user. Please feel free to let me know if this is NOT possible.

1 Answers

So this code:

<cfset x = {
    a = 1
    , b = 2
    , c = 3
}>

<cfoutput>
    <cfloop collection="#x#" item="i">
        <li>#i#</li>
    </cfloop>
</cfoutput>

Outputs the following:

  • A
  • B
  • C

Which means that i is the key of the struct defined in the collection attribute. Your code is trying to find a key in the collection (struct), but you're referencing the wrong variable.

To find the value of B, you would do StructFind(x, "b"). You don't need the cfloop either, you just need to check if the key exists, then get the value.

<cfset someVariable = "">
<cfif structKeyExists(x, "b")>
    <cfset someVariable = structFind(x, "b")>
</cfif>
Related