• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

dynamic session variable names

New Here ,
Apr 22, 2007 Apr 22, 2007

Copy link to clipboard

Copied

I need some help with setting dynamic session variables. I use the following code:
<cfset VARIABLES[ "session."& res.system & "_Status" ] = "Unknown" /> where res.system = mysystem
If I output say #session.mysystem_Status# I get the correct value of the variable if I try to use <cfdump var="session"> the session variable is not included in output of the cfdump. And I cant uses it in any other functions except for cfouput. If I try
<cfif evaluate("session.#monitors [1]#_Status") eq "Unknown"> Unknown</cfif> where monitors[1] is "mysystem" I get a error that says the session variable is undefined.

Please help 🙂
TOPICS
Advanced techniques

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 22, 2007 Apr 22, 2007

Copy link to clipboard

Copied

r34220 wrote:
> I need some help with setting dynamic session variables. I use the following
> code:
> <cfset VARIABLES[ "session."& res.system & "_Status" ] = "Unknown" /> where
> res.system = mysystem
> If I output say #session.mysystem_Status# I get the correct value of the
> variable if I try to use <cfdump var="session"> the session variable is not
> included in output of the cfdump. And I cant uses it in any other functions
> except for cfouput. If I try
> <cfif evaluate("session.#monitors [1]#_Status") eq "Unknown"> Unknown</cfif>
> where monitors
[1] is "mysystem" I get a error that says the session variable
> is undefined.
>
> Please help :)
>

of course it is not defined because with <cfset VARIABLES[ "session."&
res.system & "_Status" ] = "Unknown" /> you are setting a local
VARIABLES scope var named "session.mysystem_Status", not a SESSION scope
variable.

--
Azadi Saryev
Sabai-dee.com
Vientiane, Laos
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 23, 2007 Apr 23, 2007

Copy link to clipboard

Copied

LATEST
You may not be that familiar with coldfusion scope structures. Azadi's point is that Variables["somevar"] only sets variables in the local or Variables scope. If you want to use the scope structure notation with session variables, you need to use the following syntax: Session["someVar"]

Try:

<cfset Session["#res.system#_Status"] = "Unknown" />

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation