Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation from source code
Components
gb
gb.args
gb.cairo
gb.chart
gb.clipper
gb.complex
gb.compress
gb.crypt
gb.data
gb.db
gb.db.form
gb.db.mysql
gb.db.odbc
gb.db.postgresql
gb.db.sqlite2
gb.db.sqlite3
gb.db2
gb.dbus
gb.dbus.trayicon
gb.debug
gb.desktop
gb.desktop.gnome.keyring
gb.desktop.x11
gb.eval
gb.eval.highlight
gb.form
gb.form.dialog
gb.form.editor
gb.form.htmlview
gb.form.mdi
gb.form.print
gb.form.stock
gb.form.terminal
gb.gmp
gb.gsl
gb.gtk
gb.gtk.opengl
gb.gtk3
gb.gtk3.opengl
gb.gtk3.webview
gb.gui
gb.gui.opengl
gb.gui.qt
gb.gui.qt.ext
gb.gui.qt.opengl
gb.gui.qt.webkit
gb.gui.trayicon
gb.gui.webview
gb.hash
gb.highlight
gb.image
gb.image.effect
gb.image.imlib
gb.image.io
gb.inotify
gb.jit
gb.libxml
gb.logging
gb.map
gb.markdown
gb.media
gb.media.form
gb.memcached
gb.mime
gb.mongodb
gb.mysql
gb.ncurses
gb.net
gb.net.curl
gb.net.pop3
gb.net.smtp
gb.openal
gb.opengl
gb.opengl.glsl
gb.opengl.glu
gb.opengl.sge
gb.openssl
gb.option
gb.pcre
gb.pdf
gb.poppler
gb.qt4
gb.qt4.ext
gb.qt4.opengl
gb.qt4.webkit
gb.qt4.webview
gb.qt5
gb.qt5.ext
gb.qt5.opengl
gb.qt5.webkit
gb.qt5.webview
gb.qt6
gb.qt6.ext
gb.qt6.opengl
gb.qt6.webview
gb.report
gb.report2
gb.scanner
gb.sdl
gb.sdl.sound
gb.sdl2
gb.sdl2.audio
gb.settings
gb.signal
gb.term
gb.test
gb.util
gb.util.web
gb.v4l
gb.vb
gb.web
_Request_Get
_Request_Post
Application
CGI
jsoncollection
Request
Response
Session
_get
_put
Abandon
CookiePath
Exist
Id
Keys
Load
Modified
Prefix
Save
Timeout
Unique
URL
WebPage
gb.web.feed
gb.web.form
gb.web.gui
gb.xml
gb.xml.html
gb.xml.rpc
gb.xml.xslt
Controls pictures
Deprecated components
Developer Documentation
Development Environment Documentation
Documents
Error Messages
Gambas Playground
How To's
Language Index
Language Overviews
Last Changes
Lexicon
README
Search the wiki
To Do
Topics
Tutorials
Wiki License
Wiki Manual

Session (gb.web)

This class is used for managing sessions.

This class is static.

This class acts like a read / write static array.

Static properties
CookiePath   Return or set the path of the session cookie.
Id   Returns the session identifier.
Keys   Return the list of all keys associated with a value in the session as a string array.
Modified   Return or set if a session has been modified, and so should be saved to the disk.
Path   Return the session file path.
Prefix   Return or set the session identifier prefix.
Size   Return the session file size.
Timeout   Returns or sets the maximum duration of a session in seconds.
Type   Return or set the session type.
Unique   Return or set if the session must be unique.

Static methods
Abandon   Drops the current session.
Exist   Return if a specific key is associated with a value in the session.
Load   Reloads the session from the disk.
Save   Saves the session to the disk.

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.