Class wwSession

Tracking users through a site by keeping state information in a Session table.

wwSession provides a server centric user state tracking mechanism that is backed by generic data storage mechanism. Essentially you tie an Id (typically an HTTP Cookie) to a Session record which can contain any number of values that are stored in the session table as XML encoded data.

A session object allows your application to maintain a visitors state throughout a visit through your site. Through the unique ID that identifies this user you can store user specific information in the session store and retrieve on subsequent hit. You can think of this object of a generic data record for the user without having to create a specific table and field for each value to store temporarily.

Session can automatically be enabled in Web Connection using wwProcess::InitSession() which enables session management for one or all requests depending on where it is called.

wwSession uses a table to track user session information and can use either Fox tables or SQL server. Because of the table format Web Connection Sessions can work across machines although SQL Server sessions are recommended for this scenario for performance reasons.

Class Members

MemberDescription

CreateTable

This method creates a new session table if one doesn't exist yet or if you want to create a new one manually. This method is called automatically when a session is accessed.

o.CreateTable()

DeleteSession

Physically removes a Session record from the session table. Note that this behavior is different than EndSession() which times out a session record.

o.DeleteSession(lcId)

EndSession

Shuts down the current session for the user.

o.EndSession(lcSessionId)

GetField


Retrieves a value from a field in the session table. This method mainly exists for your own custom fields that you might add to the session table for performance or query purposes. Since fields can be queried directly via SQL commands and VPF data commands they perform much better than Session variables.

o.GetField(lcFieldName)

GetSessionId

Retrieves the user's current SessionId. This value is valid only after you've made a call to IsValidSession, NewSession or LocateSession.

o.GetSessionId()

GetSessionVar

Returns a session variable from the Session object.

o.GetSessionVar(lcVarName)

GetUserId

Returns the value from the UserID field of the current session. Note, a user ID is a manually assigned value, which typically is used to cross reference an application key such as a PK into a customer table. The Session ID is a random generated key while the user ID tends to be a user assigned value.

o.GetUserId()

IsValidSession

This method is responsible for verifying a session id. It looks for the ID in the Session table and if found returns .T. other .F. It also loads the oData member with the content of the session record.

o.IsValidSession(lcSessionId)

LocateSession

Low level method that tries to load a session and set the oData member. If found the oData member is set. If not found the oData member is set to a blank record. This is a low level method and it should usually not be called directly. Use IsValidSession instead which calls this method and then updates the timestamp and browser info.

o.LocateSession(lcID)

NewSession

This method creates a new Session record for the current user. New sessions should be created when the session doesn't already exist. The following example demonstrates:

o.NewSession(lcUserId)

OpenTable

Low level method used to open the session table.

o.OpenTable()

Reindex

Packs and reindexes the session file. You can optionally specify a cut off date/time before which entries will be deleted to allow clearing out old session detail.

o.Reindex(ltPurgeDateTime)

SetField

Sets the value of a custom field in the Session table.

o.SetField(lcFieldName, lvValue)

SetSessionID

Overrides the current SessionID's value to a new value.

o.SetSessionID(lcID)

SetSessionVar

Sets a Session variable to a specified value. All values must be passed in as strings.

o.SetSessionVar(lcVarName, lcValue)

SetUserId

Note, a user ID is a manually assigned value, which typically is used to cross reference an application key such as a PK into a customer table. The Session ID is a random generated key while the user ID tends to be a user assigned value.

o.SetUserId(lcUserId)

TimeoutSessions

Deletes all sessions that have timed out.

o.TimeoutSessions(lnSeconds)

cDataPath

Name of the path where the table lives.

cSessionID

The Session ID of the currently accessed session.

cTableName

Name of the table. Note this should be just the table name. Use cDataPath for explicit pathing on the table.

lDontSaveSession

You can set this flag to cause an active Session not write out the session content when the object goes out of scope.

lNoFileCheck

Performance operation that skips the check for the file's existence before opening it when set to .T. Since sessions are accessed on every hit, if you know you have the table already in place there's no need to check for it.

nSessionTimeout

The timeout value in seconds for a user's session. If the session is idle for this amount of seconds the session is deleted.

oRequest

Optional: An instance of the wwRequest object. This object is used when creating a new session to retrieve the client's IP address and browser and store it in the IP and Browser fields respectively.

See also:

Class wwSession | Configuring Web Connection for use with SQL Server | wwProcess::InitSession

© West Wind Technologies, 1996-2018 • Updated: 11/17/15
Comment or report problem with topic