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.
Session("name") = nameResponse.Write "Welcome " & Server.HTMLEncode(Session("name"))Response.Write Session.Contents.CountSession.Abandon ends the current session after the current request completes:
Session.AbandonRemove all values while retaining the current session:
Session.Contents.RemoveAllOr remove one named value:
Session.Contents.Remove("name")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") = languageCopy 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>"
NextIf IsEmpty(Session("userid")) Then
Response.Redirect "lg-login.php"
End IfFor protected pages, redirecting unauthenticated users is usually clearer than rendering part of the protected page and then stopping execution.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.