Greg's Blog

helping me remember what I figure out

Accessing the Session Variable Structure

| Comments

Following on from the article on clearing your application and session variables article, here I’ll focus on accessing the structure in which these variables are stored and outputing their names and values. In essence we will be looping over the structure and display the session variable value and name. Since the information is stored in a structure you will need to set the attributes collection and item of your <cfloop> tag, where the collection you are accessing is called session (or application if you wanted to look at that structure). The variable in item, is set to i, this is what we are going to output. The page would look as follows.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>

<html>
<head>
  <title>Displaying all session variables</title>
</head>

<body>
<cfloop collection=”#session#” item=”i”>
  <cfoutput>#i# - #session[i]#<br /></cfoutput>
</cfloop>

</body>
</html>

In the output i will represent the session variable name and the array syntax (#session[i]#) will output the actual value of the session variable. There you go all set now you easily see what values have been set for your session variables.