Session variables and arrays in Classic ASP

A Session variable is a named value stored for one visitor's Classic ASP session. Store compact values such as a user ID, language choice or workflow flag rather than sensitive plaintext credentials or large objects.

Create a Session variable

Session("name") = name

Read a Session variable

Response.Write "Welcome " & Server.HTMLEncode(Session("name"))

Count Session values

Response.Write Session.Contents.Count

End or clear Session state

Session.Abandon ends the current session after the current request completes:

Session.Abandon

Remove all values while retaining the current session:

Session.Contents.RemoveAll

Or remove one named value:

Session.Contents.Remove("name")

Store an array in Session

Dim language(3)
language(0) = "ASP"
language(1) = "PHP"
language(2) = "Python"
language(3) = "JavaScript"

Assign the array to a Session item:

Session("my_languages") = language

Copy it back to a local variable:

Dim savedLanguages
savedLanguages = Session("my_languages")

Read one array element:

Response.Write Session("my_languages")(0)

Or loop through the stored array:

For Each item In Session("my_languages")
  Response.Write Server.HTMLEncode(item) & "<br>"
Next

Use Session state for access checks

If IsEmpty(Session("userid")) Then
  Response.Redirect "lg-login.php"
End If

For protected pages, redirecting unauthenticated users is usually clearer than rendering part of the protected page and then stopping execution.


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer