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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Viewing Session 2

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
Is there an easy way to view all the session values without having to know the names of each one? How? I have a little snippet that does it with Cookies but can't find one for sessions. Don
pc@accesscom.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT (only when I have to!)
 
'How many session variables are there?
response.write "There are " & Session.Contents.Count &_
&quot; Session variables<br>&quot;

dim cName, i
for each cName in Session.Contents
'Is this session variable an array?
if IsArray(Session(cName)) then
'Yes: loop through each element one at a time
for i = lbound(Session(cName)) to ubound(Session(cName))
response.Write cName & &quot;(&quot; & iLoop & &quot;) - &quot; &_
session(cName)(iLoop) & &quot;<BR>&quot;
next
else
response.write cName & &quot; - &quot; &_
session.contents(cName) & &quot;<BR>&quot;
end If
next
br
Gerard
 
You may want to try this way to trap 2 dimensional array / sessions as well

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<TITLE> Sessions </TITLE>
</HEAD>

<BODY>
<%
Dim strSessionObjectName
Dim intLoop 'x in the arrays
Dim intLoop2 'y in the two dimensional array(y,x)
Dim strStaticObjectName 'these are objects that cannot be shown:NOTE: this should NEVER show anything
'if you want your ASP application to be scalable...storing objects in a session
'object is a NO-NO...

'Use a For Each ... Next to loop through the entire contents collection
For Each strSessionObjectName in Session.Contents


'Is this session variable an array?
If IsArray(Session(strSessionObjectName)) then

'If it is an arra y, loop through each element one at a time
'Name of array
Response.Write &quot;<B>&quot; & strSessionObjectName & &quot;</B> (array)<br>&quot;

'Loop through one dimensional array...
On Error Resume Next 'just to handle the array dimensions (two vs one) - you could add code for other dimensions...
For intLoop = LBound(Session(strSessionObjectName)) to UBound(Session(strSessionObjectName))
Response.Write &quot;<b>&quot; & strSessionObjectName & &quot;(&quot; & intLoop & &quot;)</b> = &quot; & _
Session(strSessionObjectName)(intLoop) & &quot;<BR><BR>&quot;
Next

intLoop = 0
'Loop through two dimensional array...
For intLoop = LBound(Session(strSessionObjectName), 2) to UBound(Session(strSessionObjectName), 2)
For intLoop2 = LBound(Session(strSessionObjectName), 1) to UBound(Session(strSessionObjectName), 1)
Response.Write &quot;<b>&quot; & strSessionObjectName & &quot;(&quot; & intLoop2 & &quot;,&quot; & intLoop & &quot;)</b> = &quot; & _
Session(strSessionObjectName)(intLoop2, intLoop) & &quot;<BR><BR>&quot;
Next
Next

Else


'List object names and list session name/value pairs
If IsObject(Session(strSessionObjectName)) Then
Response.Write &quot;<b>&quot; & strSessionObjectName & &quot; is an object...&quot;
Else
Response.Write &quot;<b>&quot; & strSessionObjectName & &quot;</b> = &quot; & Session.Contents(strSessionObjectName) & _
&quot;<BR><BR>&quot;
End If

End If
Next


'Static Objects

For Each strStaticObjectName in Session.StaticObjects
Response.Write &quot;<B>&quot; & strStaticObjectName & &quot;</B> (static object)<BR><BR>&quot;
Next
%>
</BODY>
</HTML>
 
Hi,

Thanks a lot! They both look like they'll do what I need, though I won't be ably to try them until Tuesday. Don
pc@accesscom.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT (only when I have to!)
 
Both work like a charm. Thanks! I ended up using the second one just to be sure I am not missing anything. Don
pc@accesscom.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT (only when I have to!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top