Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to store multiple values in a single session variable

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
0
0
US
I'd like to figure out how to store multiple values in a single session variable. This is for a login application, where the user can have multiple user_types. So when user logs in, I want to create a session variable that stores all of that user's user_types. For example if a user with user_id of 3 logs in, I want to query the user_type_match table for all of the user_type_id's where user_id equals 3. Then store all the matching user_type_id's, whether it be one, two, or five, in a single session variable. That way, as an already logged in user tries to enter different areas of the site, I can automatically know if they have access to that area.

Here's the query to get all the user's user_type_id's:
Code:
<cfquery name="get_user_types" datasource="#app.ds#">
  SELECT user_id, user_type_id
  FROM user_type_match
  WHERE user_id = #session.user_id#
</cfquery>

<cfif get_user_types.recordcount GT 0>
  Here's where I would set the session variable ...if I knew how.
</cfif>

Any ideas?
 


a list, structure or array will work.

Look in documentation for more info on each
 
I'm familiar with the concepts of lists, structures, and arrays. I'm not familiar with how to create a session variable that represents a list, structure, or array, nor have I been able to find any examples of how to do this, hence my posting on this forum.

Can anyone show me how to do this?
 

First you must set your cfapplication tag on application.cfm prefered. ex:
<cfapplication name="myapp" clientmanagement="Yes" sessionmanagement="Yes" setclientcookies="Yes">

Then;

List or string:

<cfset session.thisUser_id = get_user_types.user_id>
<!--- sets the value in session scope --->
<cfset session.thisUser_type_id = valueList(get_user_types.user_type_id)>
<!--- sets the value in session scope as a comma del. list --->

Then just write some logic that checks the list for the value you're looking for....If they have it let them in or whatever. You can create a second list to track where they have been as well.

Follow the same logic for sturcture or array.

Good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top