Skip to main content
Version: 20 R7 BETA

Session

Session : 4D.Session

ParameterTypeDescription
Function result4D.SessionSession object
History
ReleaseChanges
20 R5Support of remote client and stored procedure sessions
18 R6Added

Description

The Session command returns the Session object corresponding to the current user session.

Depending on the process from which the command is called, the current user session can be:

For more information, see the Session types paragraph.

If the command is called from a non supported context (single-user application, scalable sessions disabled...), it returns Null.

Web sessions

The Session object of web sessions is available from any web process:

  • On Web Authentication, On Web Connection, and On REST Authentication database methods,
  • code processed through 4D tags in semi-dynamic pages (4DTEXT, 4DHTML, 4DEVAL, 4DSCRIPT/, 4DCODE)
  • project methods with the "Available through 4D tags and URLs (4DACTION...)" attribute and called through 4DACTION/ urls,
  • On Mobile App Authentication and On Mobile App Action database methods for mobile requests,
  • ORDA functions called with REST requests.

For more information on web user sessions, please refer to the Web Server Sessions section.

Remote client sessions

The Session object of remote client sessions is available from:

  • Project methods that have the Execute on Server attribute (they are executed in the "twinned" process of the client process),
  • Triggers,
  • On Server Open Connection and On Server Shutdown Connection database methods.

For more information on remote user sessions, please refer to the Remote client user sessions paragraph.

Stored procedures session

All stored procedure processes share the same virtual user session. The Session object of stored procedures is available from:

  • methods called with the Execute on server command,
  • On Server Startup, On Server Shutdown, On Backup Startup, On Backup Shutdown, and On System event database methods

For information on stored procedures virtual user session, please refer to the 4D Server and the 4D Language page.

Example

You have defined the action_Session method with attribute "Available through 4D tags and URLs". You call the method by entering the following URL in your browser:

IP:port/4DACTION/action_Session
  //action_Session method
Case of
:(Session#Null)
If(Session.hasPrivilege("WebAdmin")) //calling the hasPrivilege function
WEB SEND TEXT("4DACTION --> Session is WebAdmin")
Else
WEB SEND TEXT("4DACTION --> Session is not WebAdmin")
End if
Else
WEB SEND TEXT("4DACTION --> Session is null")
End case

See also

Session storage
Session API
Web server user sessions