comp • gb.web • session

Session (gb.web)

This class is used for managing sessions.

This class is static.
This class acts like a
Returns the value of a session variable from its key.
read
/
Register a session variable.
write
static array.

Static properties

Static methods
Return or set the path of the session cookie.
CookiePath  
Returns the session identifier.
Id  
Return the list of all keys associated with a value in the session as a string array.
Keys  
Return or set if a session has been modified, and so should be saved to the disk.
Modified  
Path  
Return or set the session identifier prefix.
Prefix  
Size  
Returns or sets the maximum duration of a session in seconds.
Timeout  
Type  
Return or set if the session must be unique.
Unique  
Drops the current session.
Abandon  
Return if a specific key is associated with a value in the session.
Exist  
Reloads the session from the disk.
Load  
Saves the session to the disk.
Save  

What is a session?

A session allows you to keep the value of variables between two HTTP requests.

A session is a collection-like container identified by an arbitrary unique string returned by the Session.Id property.

That identifier has the following form: <PREFIX>:<KEY>

  • <PREFIX> is the prefix set to the Session.Prefix property, or the client IP address if no prefix is set.

  • <KEY> is a 24 hexadecimal digits random number.

For example: 10.254.3.151:CFA76E086C00E18CF07A8EC

The session identifier is stored in a cookie named 'SESSION' in the client browser.

Storing values in session

The session can store values associated with string keys. You can store as many values as you want, but there are restrictions: only native datatypes, arrays, and collections can be used.

The session contents are stored in the following file:

"/tmp/gambas." &/ System.User.Id &/ "session" &/ Session.Id

The session is automatically restored at program launch.

Session creation

A newly session is automatically created as soon as you store a session variable, and no session currently exists (i.e. Session.Id is NULL).

If you call Response.Begin too early, the session cannot be created, as the HTTP headers have already been sent. You have two solutions then:

Session destruction

You can abandon a session by using the Abandon method.