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.
Session.property|method([parameters])
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.
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. |
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. |
The Session.LastHit property is a DateTime value, indicating the date and time of the user's last request.
This property is read only.
tLastHit = Session.LastHit
The LastHit property will always be 0 unless the session is committed by assigning at least one session variable to it.
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.
Session.Timeout = nTimeout
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.
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.
Session.Abandon
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.
The Session.GetSessionID method returns the session id, a unique identifier that is generated by FoxWeb when a user session is created.
Session.GetSessionID()
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.
The Session.GetVar method returns the value of a previously stored session variable.
vVarValue = Session.GetVar(cVarName)
The Session.GetVarArray method returns an array containing all previously stored session variables.
nTotVars = Session.GetVarArray(@aSessionVars)
The Session.InitVars method Enables Session support for the current request.
Session.InitVars()
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.
The Session.Remove method instructs FoxWeb to destroy a previously stored session variable.
Session.Remove(cVarName)
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.
Session.SetVar(cVarName, vVarValue)