Session
Module Session

The Session module provides for persistent storage of data across HTTP requests.


Method PrototypeDescription
Function Contents() As Dictionaryget all the key/value pairs stored with this session
Function Count() As Integerget the number of key/value pairs in this session
Function HasKey(key As String) As Booleandoes the session contain the given key?
Function ID() As Stringget the unique session identifier
Function Lookup(key As String, default as Variant) As Variantget the value for a key, or the given default value if no such key is in the session
Function Name() As Stringget the name of the session ID parameter
Public Sub SetCookie(name As String, value As String, expiration As Date=Nil, path As String="/", domain As String="", secure As Boolean=false, httpOnly As Boolean=false)set a cookie (see details)
Sub Remove(key As String)remove a key/value pair from the session
Sub Start(name As String="")resume or create a session for this user (if name is not specified, "YUMASESSID" is used by default)
Function Started() As Booleandetermine whether a session has been started
Sub Stop()close the session and save all data on the server
Sub Value(key As String, Assigns value As Variant)store a new key/value pair, or replace the value of an existing key


PropertyDescription
MinutesToLive As Integerhow long to allow between uses before the session times out (defaults to 15 minutes)


A web application is really a series of discrete requests to the web server. Each request invokes a (possibly different) Yuma script or HTML file. To give the user the illusion of interacting with a single application, by carrying data (such as user name, shopping cart items, etc.) from one page to the next, requires some extra effort as compared to a desktop application.

The Session module makes this process straightforward. To store persistent daat from page to page, follow these steps:

1. Call Session.Start somewhere near the top of each Yuma script that needs to read or write session data. Pass in a unique name for your application. If you like, you can also change Session.MinutesToLive to control how long the user can be idle before their session is deleted.

2. Treat "Session" like a dictionary, calling Session.Value, Session.Lookup, and so on. Or if you need to get an actual Dictionary of the same data, use Session.Data.

3. It's not strictly necessary to call Session.Stop, as that will be called automatically when your Yuma script exits. (But it doesn't hurt, either.)

The session data is stored in a file on the server, and persists even across server restarts. It is stored under the session ID, which is generated randomly for each new session. The session ID is automatically stored in a cookie (using the session name) in Session.Start; if you want to avoid reliance on cookies, you could also store Session.ID in, say, a query parameter of a form you expect the user to submit.