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



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.



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



Shuts down the current session for the user.



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.



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



Returns a session variable from the Session object.



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.



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.



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.



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:



Low level method used to open the session table.



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.



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

o.SetField(lcFieldName, lvValue)


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



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

o.SetSessionVar(lcVarName, lcValue)


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.



Deletes all sessions that have timed out.



Name of the path where the table lives.


The Session ID of the currently accessed session.


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


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


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.


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


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-2024 • Updated: 11/17/2015
Comment or report problem with topic