So, Session Variables Hey? Ok here are a couple of ways of using them.
Here I am going to make a session variable from a previous article, this would be a random ID.
http://outsourcehouse.co.za/2010/06/14/asp-random-string/
Ok so here we go.
<%
Dim random_id
Set random_id = CreateObject(“Scriptlet.TypeLib”)
random_id = mid(random_id.GUID,2,36)
%>
<% session(“user_random_id”) = random_id %>
This would make a session variable called user_random_id and would assign a random ID to it.
Now it is impossible for you to see what sessions have been created, so this is a nice way to see what session variables are being used. I normally save this as test_my_session.asp. Here is the code:
test_my_session.asp
<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”65001″%>
Session Variables -
<% =Session.Contents.Count %>
Found<br>
<br>
<%
Dim item, itemloop
For Each item in Session.Contents
If IsArray(Session(item)) then
For itemloop = LBound(Session(item)) to UBound(Session(item))
%>
<% =item %>
<% =itemloop %>
<font color=blue>
<% =Session(item)(itemloop) %>
</font><BR>
<%
Next
Else
%>
<% =item %>
<font color=blue>
<% =Session.Contents(item) %>
</font><BR>
<%
End If
Next
%>
<hr>
</font>
<p><font face=arial> Application Variables -
<% =Application.Contents.Count %>
Found<br>
<br>
<%
For Each item in Application.Contents
If IsArray(Application(item)) then
For itemloop = LBound(Application(item)) to UBound(Application(item))
%>
<% =item %>
<% =itemloop %>
<font color=blue>
<% =Application(item)(itemloop) %>
</font><BR>
<%
Next
Else
%>
<% =item %>
<font color=blue>
<% =Application.Contents(item) %>
</font><BR>
<%
End If
Next
%>
</font> </p>
Now we want all of sessions to be killed. A very simple way of doing this is this:
clear_my_sessions.asp
<% Session.Abandon %>
session cleared
I hope that helps.
