Session Object

Description

The Session object can be used to store data needed for a particular user-session. As explained in the Session Management topic, HTTP is a stateless protocol, which means that information is not maintained between requests of a particular user. The Session object is FoxWeb's solution to this problem. Variables stored in the Session object are not discarded when the user jumps from page to page in the application. These variables persist for the entire user-session.

FoxWeb automatically creates a user session when a FoxWeb script is requested by a user who does not already have a session. The server destroys the user session when the session times out or is abandoned with the Session.Abandon method.

A common use for the Session object is to store user preferences that need to be maintained throughout the session. For example, if a user indicates that they prefer not to view the application in a foreign language, you could store that information in the Session object. For more information on the Session object, refer to the Session Management topic.

Syntax

Session.property|method([parameters])

Remarks

Session state can only be maintained for browsers that support cookies.

Even though a new user session is created if the user does not have a session yet, sessions are not maintained past the completion of the request, unless the script saves one or more variables with the Session.SetVar method.

Properties

LastHit The date and time of the user's last request.
Timeout The period of inactivity in minutes, after which a user session expires.
Token This property can be used to support sessions on browsers with cookies turned off.

Methods

Abandon Instructs FoxWeb to destroy the session and release all session variables.
GetSessionID Returns the Session ID -- a unique character sequence. identifying a user session.
GetVar Returns the value of a previously saved session variable.
GetVarArray Returns an array containing all previously saved session variables.
InitVars Enables Session support for the current request -- only needed if Session Support option is disabled.
Remove Instructs FoxWeb to release a session variable.
SetVar Stores a session variable for use in the current and subsequent requests.

LastHit Property

Description

The Session.LastHit property is a DateTime value, indicating the date and time of the user's last request.

This property is read only.

Syntax

tLastHit = Session.LastHit

Remarks

The LastHit property will always be 0 unless the session is committed by assigning at least one session variable to it.


Timeout Property

Description

The Session.Timeout property specifies the timeout period in minutes of the current user session. If the user does not request a script within the timeout period, the session ends and all session variables are destroyed.

This property is read/write.

Syntax

Session.Timeout = nTimeout

Parameters

nTimeout
A numeric value indicating the number of minutes that a user can remain idle. If nTimeout is exceeded the user session is terminated.

Token Property

Description

The value of this property can be inserted in URLs to enable session support for browsers that don't support cookies, or have cookies disabled. For details please refer to the Session Management topic.

This property is read only.


Abandon Method

Description

The Session.Abandon method instructs FoxWeb to terminate a session and destroy all the session variables associated with it. If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.

Syntax

Session.Abandon

Remarks

A new session with the same session id is created as soon as a session is abandoned. Just as with any other session, this new session is not retained unless at least one session variable is associated with it.


GetSessionID Method

Description

The Session.GetSessionID method returns the session id, a unique identifier that is generated by FoxWeb when a user session is created.

Syntax

Session.GetSessionID()

Remarks

A new session id is assigned to the same user after each request, unless the session is committed, by associating at least one session variable with it.


GetVar Method

Description

The Session.GetVar method returns the value of a previously stored session variable.

Syntax

vVarValue = Session.GetVar(cVarName)

Parameters

cVarName
A character value, specifying the name of the session variable whose value is to be retrieved.
vVarValue
Returns the value of the session variable cVarName. This value can be of type Character, Number, DateTime, Date and Logical.

GetVarArray Method

Description

The Session.GetVarArray method returns an array containing all previously stored session variables.

Syntax

nTotVars = Session.GetVarArray(@aSessionVars)

Parameters

aSessionVars
The array that gets populated with the names and values of session variables. This parameter must be passed by reference, by preceding it with an "@" character.
nTotVars
Returns the total number of session variables found.

InitVars Method

Description

The Session.InitVars method Enables Session support for the current request.

Syntax

Session.InitVars()

Remarks

You only need to call this method if you have disabled the Session Support option in the FoxWeb configuration. The InitVars method will occasionally attempt to send a cookie to the browser, so you must call it before any output is returned by your script.


Remove Method

Description

The Session.Remove method instructs FoxWeb to destroy a previously stored session variable.

Syntax

Session.Remove(cVarName)

Parameters

cVarName
A character value, specifying the name of the session variable being deleted.

SetVar Method

Description

The Session.SetVar method creates a session variable for the current user session and assigns a value to it. If a session variable with the same name already exists, then its value is updated.

Syntax

Session.SetVar(cVarName, vVarValue)

Parameters

cVarName
A character value, specifying the name of the session variable being created or updated.
vVarValue
The value that is to be stored to the session variable cVarName. This value can be of type Character, Number, DateTime, Date and Logical.

© Aegis Group