coldfusion - Can I use a variable as the variable name when defining a session variable? -
is possible define session variable using variable name of session variable? have not found situation when researching how define session variable.
i novice cfml user, , here situation attempting set up. hope it's not wordy , confusing.
i have code on each page shoots me email alert when given site user accesses particular page during user's session. works fine. but, want email alert triggered first time user accesses page -- don't care additional page visits page user during user's session.
i need define session variable unique "that user/that page" combination. whenever user accesses page, variable. if there match, means user visited page during user session, , don't trigger email alert.
for "that user" part, have defined session variable user when user logged in (session.name).
for "that page" part, define unique variable @ top of each page - example
<cfset page_filename = 'index.cfm'>
conundrum: how combine both parts (name , page_filename) single unique session variable when 1 of 2 parts (page_filename) variable.
so far, i've tried defining "session.page_alert" using page_filename session.name
<cfset session.page_alert = '#page_filename##session.name#'>
but, becomes useless user visits page, since #page_filename# part different on each page, , therefore unique session variable pertains new page , not previous page. if user returns previous page, session variable no longer refers it, appears if user visiting first page again when user had been there.
ideally, want like
<cfset session.#page_filename# = '#page_filename##session.name#'>
-- unique combination persist user's session. but, cfml barfs when this, because defining session variable variable. missing obvious solution want do? hope not confusing. thank can provide!
=============================================================== `
<!--- username variable session.name defined upon user login ---> <!--- test display existence of variable ---> <cfoutput> <p>session.name = #session.name# </cfoutput> <!--- part works fine ---> <!--- define page_filename local variable @ top of each page ---> <cfset page_filename = 'index.cfm'><!--- example 1 page ---> <!--- test display existence of variable ---> <cfoutput> <p>page_filename = #page_filename# </cfoutput> <!--- part works fine ---> <!--- attempt define session variable using page_filename variable defined above ---> <cfset session[page_filename] = '#page_filename##session.name#'> <!--- test display after attempt define session variable ---> <cfoutput> <p>session.page_filename = #session.page_filename# </cfoutput> <!--- produces cf error msg stating "page_filename undefined in session" --->`
<cfset session[page_filename] = '#page_filename##session.name#'>
update here's modification code request
scope in place session
scope. please compare have changing code session
scope.
<!--- username variable session.name defined upon user login ---> <cfset request.name = "username foo"> <!--- test display existence of variable ---> <cfoutput> <p>request.name = #request.name# </cfoutput> <!--- part works fine ---> <!--- define page_filename local variable @ top of each page ---> <cfset page_filename = 'index.cfm'><!--- example 1 page ---> <!--- test display existence of variable ---> <cfoutput> <p>page_filename = #page_filename# </cfoutput> <!--- part works fine ---> <!--- attempt define session variable using page_filename variable defined above ---> <cfset request[page_filename] = '#page_filename##request.name#'> <!--- test display after attempt define session variable ---> <cfoutput> <p>request.page_filename = #request[page_filename]# </cfoutput>
run me on trycf: http://trycf.com/scratch-pad/pastebin?id=w6ksywzc
Comments
Post a Comment